Google Distance Matrix API - Wrong calculated distances if addresses incomplete

33 views Asked by At

We have a form where users can enter 2 addresses / POIs A and B. We need to calculate the distance between these 2 after submitting. Unfortunately, some users omit important data of the address like the city name. Right now the Google Distance Matrix API is just using the first possible match it can find.

Example:

Address A: "Berlin Alexanderplatz"

Address B: "Kneipenviertel" (which means bar district in english)

If one would ask a real person for the distance between the two points, that person would assume "Kneipenviertel" is in the same city, since this information is omitted, so that person would "autocorrect" address B to "Kneipenviertel Berlin" and then return the desired information.

The Google Distance Matrix API however does not seem to work like this and uses a random "Kneipenviertel" in a totally different city that is hundreds of kilometres away.

The form is not changeable so I can not implement additional fields or the places API.

Is it possible to tell Google to use the (spatially) closest match if addresses are ambigous? Or is there any alternative API that provides a more intelligent calculation?

1

There are 1 answers

1
Kat On

The Distance Matrix API relies on Geocoding API in converting the addresses typed by your users into coordinates. When an address is incomplete or ambiguous like your example "Kneipenviertel", the Geocoder will try to find the best match but that match might not be what the user intended. That is the reason why using place IDs is preferred over using addresses or latitude/longitude coordinates as stated in the documentation.

You may want to consider the following solutions:

  1. To reduce user input ambiguity, make essential address fields like City mandatory.
  2. Implement Places Autocomplete API. This API suggests addresses as your user types, helping them select complete and accurate locations. You may visit Place Autocomplete service documentation for more information.