0

I have been trying to get exact address of mobile device using geocode. Here is my code

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()
  }
}

Here I am getting the address but it's not been exact address. Can I specify the boundary or range so that I can get the exact address.

  • no all google address data is correct. it's a best guess with your input (fuzzy geocoding) – Mapperz Feb 20 at 18:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.