借助百度地图api解决获取经纬坐标问题

今天做一个附近医院查询的小应用,要求根据经纬坐标计算距离,按距离由近到远排列起来,在web前端获取经纬坐标的时候发现新版本ios10和chrome浏览器在获取经纬坐标时要求服务器是https协议,否则就会报下面的警告,无法获取坐标,在IE中就没问题。

getCurrentPosition() and watchPosition() are deprecated on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See https://goo.gl/rStTGz for more details.

要解决这个问题就得把自己服务器换成https服务,或者借助第三方,我选择百度地图api解决,直接上代码!

<script src="http://api.map.baidu.com/api?v=2.0"></script>
<script>
    var geolocation = new BMap.Geolocation();
    geolocation.getCurrentPosition(function (r) {
        if (this.getStatus() == BMAP_STATUS_SUCCESS) {
            var mk = new BMap.Marker(r.point);
            var latitude = r.point.lat;
            var longitude = r.point.lng;
            //----------- 你的代码
            console.log(longitude);    //经度
            console.log(latitude);      //纬度
            //----------- 你的代码
        }
    });
</script>

这样就解决获取坐标的问题了!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容