0

I've waste a lot of time, but I'm not able to do it.

I'll appreciate help.

How to get the result of the inverse geolocation in a variable?

here is the script:

geocoder = new GClientGeocoder();
geocoder.getLocations('43.3372814,(-1.79548311)', showAddress);

function showAddress(response) {

    place = response.Placemark[0];
    point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
    marker = new GMarker(point);
    map.addOverlay(marker);
    return(place.address);
}

I've tried to do:

var address = geocoder.getLocations('43.3372814,(-1.79548311)', showAddress);

but with no result.

Really thnx for your help

kapex
  • 28,903
  • 6
  • 107
  • 121
SauronZ
  • 355
  • 3
  • 14
  • what happens when you run this code. Are there any errors ? Showing any error output, describing what happens and what doesn't and even setting up example's all go a long way to getting an answer on here – Lee Jan 19 '12 at 12:29
  • check this.hope this helps you: http://stackoverflow.com/questions/6478914/reverse-geocoding-code – Kiran Jan 19 '12 at 12:34

1 Answers1

0

as described on http://code.google.com/apis/maps/documentation/javascript/v2/services.html the second argument showAddress is the callback function. So you would have to do something like:

geocoder.getLocations('43.3372814,(-1.79548311)', showAddress);

function showAddress(response) {
  if (!response || response.Status.code != 200) {
    alert("Status Code:" + response.Status.code);
  } else {
    place = response.Placemark[0];
    point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
    marker = new GMarker(point);
    map.addOverlay(marker);
    marker.openInfoWindowHtml(
        '<b>orig latlng:</b>' + response.name + '<br/>' + 
        '<b>latlng:</b>' + place.Point.coordinates[1] + "," + place.Point.coordinates[0] + '<br>' +
        '<b>Status Code:</b>' + response.Status.code + '<br>' +
        '<b>Status Request:</b>' + response.Status.request + '<br>' +
        '<b>Address:</b>' + place.address + '<br>' +
        '<b>Accuracy:</b>' + place.AddressDetails.Accuracy + '<br>' +
        '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
  }
}
Manuel van Rijn
  • 10,170
  • 1
  • 29
  • 52