javascript - 获取当前地理位置js方法?
阿神
阿神 2017-04-11 12:34:26
0
2
433
<script type="text/javascript" >
var weizhi='{$weizhi}';
if(!weizhi){
    var geolocation = new BMap.Geolocation();
    // 创建地理编码实例      
    var myGeo = new BMap.Geocoder();
    geolocation.getCurrentPosition(function(r) {
        if (this.getStatus() == BMAP_STATUS_SUCCESS) {
            var pt = r.point;
            // 根据坐标得到地址描述    
            myGeo.getLocation(pt,
            function(result) {
                console.log(result);
                if (result) {
                    var addComp = result.addressComponents;
                    
                }
            });
        }
    });
}
</script>

报错
getCurrentPosition() and watchPosition() are deprecated on insecure origins, and support will be removed in the future. You should consider switching your application to a secure origin, such as HTTPS. See https://goo.gl/rStTGz for more details.

阿神
阿神

闭关修行中......

全部回覆(2)
阿神

获取用户地理位置必须在一个安全的环境中。比如使用了 https 协议的页面中。这么做主要是因为浏览器考虑用户的隐私安全。

这只是一个 Warning ,现在应该在非加密协议下的页面中还是可以使用,但将来会完全禁止。

阿神

<script type="text/javascript">

// 百度地图API功能
var map = new BMap.Map("allmap");
var point = new BMap.Point(116.331398,39.897445);
map.centerAndZoom(point,12);

function myFun(result){
    var cityName = result.name;
    map.setCenter(cityName);
    alert("当前定位城市:"+cityName);
}
var myCity = new BMap.LocalCity();
myCity.get(myFun);

</script>

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!