修正后的代码如下:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>精准定位</title>
    <script type="text/javascript" src="//api.map.baidu.com/api?v=3.0&ak=gHILVzmuMIlwy2Z5lE33dedbeI87UIZK"></script>
</head>
<body>
    <div id="initMap" style="display: none;"></div>

    <script>
        var zd = getLocation();

        function getLocation() {
            // 百度地图API功能
            var map = new BMapGL.Map("initMap");
            var point = new BMapGL.Point(116.331398, 39.897445);
            map.centerAndZoom(point, 12);
            var geolocation = new BMapGL.Geolocation();
            geolocation.getCurrentPosition(function (r) {
                console.log(r)
                if (this.getStatus() == BMAP_STATUS_SUCCESS) {
                    console.log('您的位置:' + r.point.lng + ',' + r.point.lat);
                    x_pi = 3.14159265358979324 * 3000.0 / 180.0;
                    x = r.point.lng;
                    y = r.point.lat;
                    z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
                    theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
                    lngs = z * Math.cos(theta) + 0.0065;
                    lats = z * Math.sin(theta) + 0.006;
                    var point = new BMapGL.Point(lngs, lats);//用所定位的经纬度查找所在地省市街道等信息
                    
                    var gc = new BMapGL.Geocoder();
                    
                    gc.getLocation(point, function (rs) {
                        var addComp = rs.addressComponents;
                        console.log(rs.address);//地址信息
                        alert(rs.address);
                    });
                }
            });
        }
    </script>
</body>
</html>

这段代码实现了调用百度地图API进行精准定位,并在弹窗中显示门牌地址

修正以下代码实现调用百度地图API进行精准定位并在弹窗中显示门牌地址并列出完整的html代码div id=initMap style=display none;div		script type=textjavascript src=apimapbaiducomapiv=30&ak=gHILVzmuMIlwy2Z5lE33dedbeI87UIZKscript		script		var zd = ge

原文地址: http://www.cveoy.top/t/topic/iU9l 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录