1.登录https://lbs.qq.com/,手机验证码登录
创建应用
2.设置域名白名单
3.调用
//通过ip获取城市 function getCityByIp() { $.getScript(‘https://apis.map.qq.com/ws/location/v1/ip?key=AICBZ-VCXKU-PGXV6-2EQJU-GXN3F-LSF64&output=jsonp&callback=setDefaultCity‘); } //设置默认城市 function setDefaultCity(res) { res = res || {}; var info = res.result && res.result.ad_info; if (info) { var province = info.province, city = info.city, _p = ‘‘, _c = ‘‘; if (province && city) { chinaRegion.forEach(function (p) { if (p.name.indexOf(province.substring(0, province.length - 1)) !== -1) { p.childs.forEach(function (c) { if (c.name.indexOf(city.substring(0, city.length - 1)) !== -1) { _p = p.name; _c = c.name; } }); } }); } indexApp.province = _p; indexApp.city = _c; } indexApp.getData(true); }
返回数据格式
setDefaultCity&&setDefaultCity({ "status": 0, "message": "query ok", "result": { "ip": "58.57.32.162", "location": { "lat": 35.05151, "lng": 118.34787 }, "ad_info": { "nation": "中国", "province": "山东省", "city": "临沂市", "district": "兰山区", "adcode": 371302 } } })