高德地图获得当前位置信息

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <script type="text/javascript">
        window._AMapSecurityConfig = {
            securityJsCode: "securityJsCode",
        };
    </script>
    <script src="https://webapi.amap.com/loader.js"></script>
    <script type="text/javascript">
        AMapLoader.load({
            key: "key",
            version: "2.0"
        }).then(() => {
            AMap.plugin('AMap.Geolocation', function () {
                AMap.plugin('AMap.Geocoder', function () {
                    var geolocation = new AMap.Geolocation();
                    var geocoder = new AMap.Geocoder();
                    geolocation.getCurrentPosition(function (_, pos) {
                        pos = pos.position.toString().split(',');
                        geocoder.getAddress(pos, function (_, result) {
                            var c = result.regeocode.addressComponent.city;
                            console.log(result.regeocode.formattedAddress + '#' + pos);
                        });
                    });
                });
            });
        });
    </script>


</body>
</html>

 

posted @ 2025-05-21 16:59  大胡子毛绒老头  阅读(208)  评论(0)    收藏  举报