开发者网址导航

js 利用百度地图接口在浏览器中获取经纬度

shake    ·  106 浏览
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=6yAoynmTPNlTBa8z1X4LfwGE"></script>
<script type="text/javascript" src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>

    var geolocation = new BMap.Geolocation();
    geolocation.getCurrentPosition(function (r) {
        if (this.getStatus() == BMAP_STATUS_SUCCESS) {
            var mk = new BMap.Marker(r.point);
            currentLat = r.point.lat;
            currentLon = r.point.lng;
            console.log(currentLat);
            console.log(currentLon);

            var pt = new BMap.Point(currentLon, currentLat);
            var geoc = new BMap.Geocoder();

            geoc.getLocation(pt, function (rs) {
                var addComp = rs.addressComponents;
                console.log(addComp);

                var city = addComp.city;
                var addComp = rs.addressComponents;
                var texts = addComp.district + " " + addComp.street + " " + addComp.streetNumber;
                //获取地理位置成功,跳转
                console.log(texts);
            });
        }
    });
0个回答
恭喜你,这是一条成功消息
!
警告哦,这是一条警告消息