首页 > 其他 > 详细

首页定位默认城市本地 调佣腾讯地图接口

时间:2021-08-21 19:55:50      阅读:28      评论:0      收藏:0      [点我收藏+]

 

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
        }
    }
})

首页定位默认城市本地 调佣腾讯地图接口

原文:https://www.cnblogs.com/blogzys/p/15170202.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!