1.
GClientGeocoder.getLatLng(): this method allows you to get location of a specific location by querying google geoserver. You need to pass two arguments, address and a callback function. That callback function is invoked with one parameter, a GLatLng object of that location, when there is a reply from this service. See example here.2.
GClientGeocoder.getLocations(): this method allows you more ability than the previous one by returning a JSON object consisting of the following information: Status (request, code), Placemark (address, AddressDetails, Accuracy, Point, coordinates,...). Moreover, it supports both standard and reverse geocoding. If you pass this method a GLatLng object instead of a String address, the geocoder will perform a reverse lookup and return a structured JSON object of the closest addressable location. See examples:geocoding-extraction
geocoding-reverse
Recently, I realized Google has added another information of data returned by this method, ExtendedData which consists of north, east, south, and west of that area. This is quite useful when positioning location on the map with appropriate zoom level. All you have to do, construct a GLatLngBounds object with these data, then call getBoundsZoomLevel() by passing this GLatLngBounds object to determine proper zoom level that fits map view port.
var getLocation = function(address) {
var geoCoder = new GClientGeocoder();
geoCoder.getLocations(
address,
function(location){
document.getElementById('txtAddressId').value = address;
//if this address is found
if(location.Status.code == 200) {
var placeMark = location.Placemark[0];
var latLngBox = placeMark.ExtendedData.LatLonBox;
//default zoom level is 7
var latlng, zoom = 7;
if(latLngBox) {
//determine zoom level if possible
var latLngBound = new GLatLngBounds(new GLatLng(latLngBox.south, latLngBox.west), new GLatLng(latLngBox.north, latLngBox.east));
zoom = map.getBoundsZoomLevel(latLngBound);
}
latlng = new GLatLng(placeMark.Point.coordinates[1], placeMark.Point.coordinates[0]);
map.setCenter(latlng, zoom);
} else {
alert('Address is not found.');
}
}
);
}