views:

245

answers:

1

I have an address, and now I need to retrieve the Lat / Lang coordinates.
At Google, they only have good examples for V2 and not V3.

I want to do the following:

var myLatLAng = getLatLang(adress);

How can I modify this code to make that happend?

function showAddress(address) {
  geocoder.getLatLng(
    address,
    function(point) {
      if (!point) {
        alert(address + " not found");
      } else {
        map.setCenter(point, 13);
        var marker = new GMarker(point);
        map.addOverlay(marker);
        marker.openInfoWindowHtml(address);
      }
    }
  );
}
A: 

You cannot return any value because getLatLng is using callback function so it can only interact with your enviroment.
You can assign it to some other variable

var lat, lng;
function showAddress(address) {
    ...
    } else {
         lat = point.lat();
         lng = point.lng();

         orExecuteOtherfunction();
    }
}

Or execute some other function that will do something with your returned point.

hsz
Yeah... that's what I feared :(. Thanks.
Steven