<!DOCTYPE html>
<html>
<head>
    <title>精准定位到门牌地址</title>
    <style>
        html, body, #map {
            width: 100%;
            height: 100%;
            margin: 0;
        }
    </style>
</head>
<body>
    <div id="map"></div>
<pre><code>&lt;script src=&quot;http://api.map.baidu.com/api?v=3.0&amp;ak=Q7hhQzxGQt1Ea0Gg1crZjrSWvtY9eqkR&quot;&gt;&lt;/script&gt;
&lt;script&gt;
    // 创建地图实例
    var map = new BMap.Map(&quot;map&quot;);
    
    // 创建定位控件
    var geolocation = new BMap.Geolocation();
    
    // 开启定位
    geolocation.getCurrentPosition(function(result){
        if(this.getStatus() == BMAP_STATUS_SUCCESS){
            // 定位成功,获取门牌地址
            var point = result.point;
            var geoc = new BMap.Geocoder();
            geoc.getLocation(point, function(rs){
                var address = rs.addressComponents;
                console.log(&quot;门牌地址:&quot; + address.province + address.city + address.district + address.street + address.streetNumber);
                alert(&quot;门牌地址:&quot; + address.province + address.city + address.district + address.street + address.streetNumber);
            });
            
            // 在地图上显示定位点
            map.centerAndZoom(point, 17);
            var marker = new BMap.Marker(point);
            map.addOverlay(marker);
        }
        else {
            // 定位失败
            console.log('定位失败:' + this.getStatus());
        }
    },{enableHighAccuracy: true});
&lt;/script&gt;
</code></pre>
</body>
</html
修正以下代码在微信内置浏览器中显示的位置偏移问题并列出完整代码!DOCTYPE htmlhtmlhead title精准定位到门牌地址titleheadbody div id=map style=width 100; height 500px;div script src=httpapimapbaiducomapiv=30&ak=Q7hhQzxGQt1Ea0Gg1crZjrSWv

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

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