I am trying to implement a feature in a Flutter app where the user will place a pin and it will return the name OR address of the place that they dropped it at, depending on what the place is. I’m using Google Place API to do this.
For example, if I dropped a pin at this mountain:
I would want the api to return Thunder Butte
.
On the other hand, if I dropped it at a specific building:
Then it should return an address something like 1234 E 78th Way
.
And finally, if I dropped a pin at this park:
Then I’d like it to return Cherry Creek State Park
.
To do this, I’ve been using the findplacefromtext
api endpoint from the Google Places API. Following this documentation, I created this url to get a list of potential matches.
Here is the url:
https://maps.googleapis.com/maps/api/place/findplacefromtext/json?
&input=
&inputtype=textquery
&types=landmark|neighborhood|natural_feature|street_address|locality
&fields=name,address,
&locationbias=circle%3A2000%4039.17168317836054%2C-105.19749451428652&key=api_key_123
(I added line breaks for clarity.)
I left input
equal to
because I was attempting to get all the results within the radius set by locationbias
. The locationbias
here is a circle with a center of the point that the user dropped in the app and a radius of 2000.
The documentation says to create a circle in locationbias
like this:
Circular: A string specifying radius in meters, plus lat/lng in decimal degrees. Use the following format:
circle:radius@lat,lng
. I replaced the:
@
, and,
with%3A
,%40
, and%2C
, respectively. Those came from the example url in the documentation.
Also notice that I restricted the type of place response to landmark
, ‘neighborhood, 'natural_feature
, street_address
, and locality
However, for each of these examples, the query will always return ZERO_RESULTS
or a completely unrelated result. Is what I’m asking for possible?