0

Hey,

I am having some trouble with Google Maps API... I have the following code:

function geocodePosition(pos) {
  geocoder.geocode({
    latLng: pos
  }, function(responses) {
    if (responses && responses.length > 0) {
      updateMarkerAddress(responses[0].formatted_address);
    } else {
      updateMarkerAddress('Cannot determine address at this location.');
    }
  });
}

However this shows the full address.... However I only want it to show the Town/City County and Country EG:
York, Yorkshire, England

Can anyone help me change my code to return this result to the function updateMarkerAddress();

Dan

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Airshow
0

I have not used Google Maps' reverse geocoding but think you will have problems achieving exactly what you want. The reason is that, whereas you may get several results, you have no control over, and no prior knowledge of, the format of their .formatted_address properties.

You may be able to loop through the .address_components array (of each result) and build the address to the required format but, again, you have no prior knowledge of what address component types are present in any particular result.

As they say in the API (admittedly with a different emphasis), "reverse geocoding is not an exact science".

Airshow

Edited by Airshow: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.