首页 > 解决方案 > 从 LatLong 获取确切地址

问题描述

我一直在尝试使用地理编码获取移动设备的确切地址。

这是我的代码

        function showPosition(position) {
    debugger;
    console.log("Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude);
    CLat = position.coords.latitude;
    Clng = position.coords.longitude;
    add = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + CLat + "," + Clng + "&key=" + _globalAPIKey;
    console.log(add);


    var geocoder = new google.maps.Geocoder();
    var latLng = new google.maps.LatLng(CLat, Clng);


    if (geocoder) {
        debugger;
        geocoder.geocode({ 'latLng': latLng }, function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                debugger;
                console.log(results[0].formatted_address);
                alert('Address:' + results[0].formatted_address);
            }
            else {
                debugger;
                //alert('Geocoding failed: ' + status);
                console.log("Geocoding failed: " + status);
            }
        }); //geocoder.geocode()
    }
}

在这里,我得到了地址,但它不是确切的地址。我可以指定边界或范围,以便我可以得到确切的地址。
或者我没有得到准确的 LatLog ,因为 Address 也是错误的。

请提供您的建议或示例代码。

感谢和问候 Rahul K Sharma

标签: google-geocoding-api

解决方案


推荐阅读