admin管理员组

文章数量:1616032

1.浏览器定位,优先调用浏览器H5定位接口,如果失败会调用IP定位。

2.本人用域名https调用正常,用电脑谷歌浏览器定位只能定位到城市,用手机定位可以具体定位;

html代码

<script src="https://api.map.baidu/api?type=webgl&v=1.0&ak=key"></script>
<div id="container" style="width: 400px;height: 400px;"></div>

js代码

<script>
    var map = new BMapGL.Map('container'); // 创建Map实例
    var point = new BMapGL.Point(116.331398,39.897445);
    map.centerAndZoom(point,12);
    var geolocation = new BMapGL.Geolocation();
    geolocation.getCurrentPosition(function(r){
        if(this.getStatus() == BMAP_STATUS_SUCCESS){
            var mk = new BMapGL.Marker(r.point);
            map.addOverlay(mk);
            map.panTo(r.point);
            alert('您的位置:' + r.point.lng + ',' + r.point.lat);
        }
        else {
            alert('failed' + this.getStatus());
        }
    });
</script>

本文标签: 浏览器地图