Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Google Maps Places API - 50km radius restriction not being enforced?

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?

Answer*

Cancel
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