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

function geocodePosition(pos) {
    latLng: pos
  }, function(responses) {
    if (responses && responses.length > 0) {
    } 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();


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".