0

Problem

According to the official Google Maps Places API documentation, the radius parameter is limited to 50,000 meters (50 km) for Autocomplete requests:

radius
The radius will automatically be clamped to a maximum value depending on the type of search and other parameters:

  • Autocomplete: 50,000 meters [...]

However, in my tests, I'm getting results located more than 50 km away from the specified center, even when setting strictBounds=true.

Code to Reproduce

@Test
void autocomplete_addresses_outside_50km_restriction() {
    var dotenv = Dotenv.configure().filename("local.env").load();
    var apiKey = dotenv.get("GOOGLE_API_KEY");
    var context = new Builder().apiKey(apiKey).build();

    // Center for the search
    var center = new LatLng(43.93578243946096, 6.0261110523814);
    var radiusInKm = 100; // Trying with 100km
    var restriction = new LocationRestriction(center, radiusInKm);

    var addresses = getAutocompleteAddress(context, "Jean Jaurès", restriction);

    var distancesInKm = Arrays
            .stream(addresses)
            .map(prediction -> getPlaceDetails(context, prediction))
            .map(placeDetail -> distanceInKms(center, toLatLng(placeDetail)))
            .toList();

    // Some results are beyond 50km
    assertThat(distancesInKm).anyMatch(distanceInKm -> distanceInKm > 50);
}

You can find the complete test code in this GitHub repository: https://github.com/phdezann/google-maps-radius-restriction

Observed Behavior

My test passes, which means I'm receiving addresses that are more than 50 km away from the search center, while the documentation clearly states a 50 km limit.

Question

Is this behavior normal?

0

1 Answer 1

0

I think the root cause maybe that this returns a street called "Av Jean Jaurès". And while the LatLng of the point of this street is outside of your radius, parts of the route are not.

Is there a chance you can try this using the Places API (New)? I know it's annoying but Google is going to deprecate the API you are currently using within the next year or two and have everyone migrate to the new one. This means even though there maybe a bug in the legacy API, it's unlikely to get fixed at this point. It would only get fixed if we can reproduce it on the new API.

The new API is also using LocationRestriction, but instead of a circle you have to define a rectangle viewport.

1
  • Unfortunately, the streets found are from cities located more than 50 km from the search center. I tested with a radius of 1000 km in my code, and it returns, for example, a street from Paris - which clearly cannot fall within the 50 km circle, as the center is located 600 km away from Paris. I agree with you that migrating to the new Places API might be a good option to explore. It seems that the 50 km limit is better enforced there, as the Java client throws an exception if the radius exceeds this limit as the implementation of TextSearchRequest.radius indicates. Commented May 5 at 9:24

Your Answer

By clicking β€œPost Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.