I am currently using the google maps api to geocode locations on the map and return the address of the street.
I currently return the address with the following code:
function codeLatLng(markerPos) {
geocoder.geocode({'latLng': markerPos}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
//Set markerAddress variable
var markerAddress = results[0].formatted_address;
alert(markerAddress);
...
But what if I don’t want to return the formatted address but a more detailed version using Address Component Types, how can I return certain address values like: http://code.google.com/apis/maps/documentation/geocoding/#Types
Help appreciated.
May I ask, why are you checking for
results[1]and then usingresults[0](or is it just a typo I should ignore)?As long as
statusisOK, there will be at least one result.Otherwise,
statuswould beZERO_RESULTS.Anyway, you can use something like this:
You can play a lot with the whole
address_componentsarray, have fun! 🙂For even more fun, have a look at the (source code of the) Google Maps API v3 Geocoder Tool at http://gmaps-samples-v3.googlecode.com/svn/trunk/geocoder/v3-geocoder-tool.html