-3

Is it possible to search nearby cities with given city or latitude longitude using geocoding API?

For example user input City A, then the result is a list of cities nearby to city A.

if not possible, do you have any suggestions for using other APIs or references that can be used?

Syaifudin Zuhri
  • 108
  • 1
  • 2
  • 11

1 Answers1

3

What you should use is Nearby Search using Places API.

You can use the radius parameter to limit the distance of nearby search and also specify the types parameter depending on what you want or need.

You can use these types on their Table 3:

  1. (regions) type collection instructs the Places service to return any result matching the following types:
  • locality
  • sublocality
  • postal_code
  • country
  • administrative_area_level_1
  • administrative_area_level_2
  1. (cities) type collection instructs the Places service to return results that match locality or administrative_area_level_3.

Ref: Table 3: Type collections supported in Place Autocomplete requests

I recommend that you should read more from their docs if you want to learn more. here's the link to get started: Places API Docs

Hope this helps.

Yrll
  • 1,619
  • 2
  • 5
  • 19
  • its only return selected location not with nearby. `params: location:-7.546839,112.226479,radius:100000, type:administrative_area_level_2` – Syaifudin Zuhri Oct 04 '22 at 04:36
  • You could only use `regions` or `cities` as types. Here's an example: `https://maps.googleapis.com/maps/api/place/nearbysearch/json?&location=-7.546839,112.226479&radius=100000&type=cities&key=YOUR_API_KEY` – Yrll Oct 04 '22 at 04:46
  • According to the [docs](https://developers.google.com/maps/documentation/places/web-service/supported_types#table3:~:text=Note%3A%20The%20types%20below%20are%20not%20supported%20in%20the%20type%20filter%20of%20a%20place%20search.), `administrative_area_level_2` is not supported as `type` filter on this Place Search. – Yrll Oct 04 '22 at 04:53
  • Only give `locality` data on my country, and in another country, some give `cities` data some only `locality`, and some mix between `locality` data and `cities` data – Syaifudin Zuhri Oct 04 '22 at 07:00
  • That's because not all nations exhibit the same administrative levels. The API isn't guaranteed to return any particular component for an address within their data set. What may be thought of as the city, such as Brooklyn, may not show up as `locality`, but rather as another component - in this case, `sublocality_level_1`. ref: [docs](https://developers.google.com/maps/documentation/geocoding/requests-geocoding#Types:~:text=The%20Geocoding%20API%20isn%27t,components%20from%20the%20response.) – Yrll Oct 04 '22 at 07:10