I am trying to build a list of products, each tagged with a sublocality
from the Google Places API.
I use the placesAutoComplete
method from the API to allow the user to search for their sublocality
while creating the product.
I then want to enable other users to search for products in a location, but this location can be a locality
, city
, or any other type that are ancestors of said sublocality
.
When the user creating the product selects a sublocality
I get back a list of types
in the response, but none of these contain a place_id
.
I thought there might be a way to find all ancestor place_id
s of a place and store the array together with the product, thus enabling the user to find a product in a place, or it's parent place or it's parent place or it's parent country, etc.
For example, the user creating the product lists it in "Rochester, NY, USA". I want other users to be able to find this product when searching for products in "Rochester", "NY" or "USA".
Is there a way to find all ancestor place_id
s of a place? Or is there another way of storing these values that I am overlooking that will enable something like this?
After plenty of searching I have found the answer I was looking for. For anyone else trying this, this is what I did:
When making a placesAutoComplete
call you can specify a piped string result_type
to specify the type of results you want to receive. I changed my current result_type
of locality with a new result_type
of country|locality|sublocality|neighborhood and now instead of receiving the one, I receive a list of results, each of a different type, and each with it's own place_id
.
A combination of the results (with duplicates filtered out) gives me exactly what I was looking for.