Get all geolocations by partial name using google maps api - google-maps

I have signed up with the Google Maps API. I can geolocate locations using the following query
url = f"https://maps.googleapis.com/maps/api/geocode/json?address={city}&key={api_key}"
I need to do a search for towns by partial name.
For example 'MyTown' is a town , but there are also towns with names which include 'MyTown' in the title, such as MyTown-By-Sea, MyTown-SomethingElse and even NiceMyTown
The above query using the API returns just the city MyTown, not the others
Is there some option I have missed to get the Google Maps API to be less specific in the response returned ?

You can use Places Autocomplete API web service. This API will return places suggestions or predictions, based on your given input.
https://maps.googleapis.com/maps/api/place/autocomplete/json
?input=MyTown (based on your example)
&location=latitude,longitude
&key=YOUR_API_KEY

Related

Whcih API should I use to auto complete cities , streets and suburbs?

I tried to find a big database of Cities , Streets and Suburbs of my country to make an autocomplete search input but I couldn't find any good source of such database...
I was thinking to use Google autocomplete API for that purpose but I couldn't understand how to get the data I need with that,
What api should I use?
The API you want to use is Places API,
https://developers.google.com/places/web-service/intro
From the Places API, the request you want to use is Place Autocomplete Requests,
https://developers.google.com/places/web-service/autocomplete
In case you're using Maps JS API there is no need to use the web services endpoints.
Autocomplete for Addresses and Search Terms is available in the JS API
https://developers.google.com/maps/documentation/javascript/places-autocomplete
Example,
https://developers-dot-devsite-v2-prod.appspot.com/maps/documentation/javascript/examples/places-autocomplete-addressform

Google Maps API: Different formats of place_id value

I'm using getQueryPredictions method to get autofill entries. The value of place_id in about 10% of returned places is a 40 characters long string that starts with "E". I'm trying to pass that place_id to google.maps.DistanceMatrixService().getDistanceMatrix method to get a distance between those places and other "normal" locations but Google does not return anything for such IDs.
You can easily get such "E" place_id if you use address "4498 INTERSTATE NORTH PARKWAY EAST SOUTHEAST" at this form from Map API Documentation It returns "EjM0NDk4IEludGVyc3RhdGUgTiBQa3d5IEUgU0UsIEF0bGFudGEsIEdBIDMwMzM5LCBVU0E" as place_id. Use that ID in any other Maps API mathods and Google won't recognize it as a valid place_id.
How can I use those weird IDs to look up distances? Or how can I transform them into normal place_ids?
I created an API key and used the referred place_id, which returned a valid response.
https://maps.googleapis.com/maps/api/place/details/json?placeid=EjM0NDk4IEludGVyc3RhdGUgTiBQa3d5IEUgU0UsIEF0bGFudGEsIEdBIDMwMzM5LCBVU0E&key=[API_KEY]
Its not specified, but not all Google Maps API can be used with place_id.
You can use the same place ID across the Google Places API and a number of Google Maps APIs. For example, you can use the same place ID to reference a place in the Places API, the Google Maps JavaScript API, the Google Maps Geocoding API, the Google Maps Embed API and the Google Maps Roads API.
For your getDistanceMatrix to work, your destinations[] should either be string, LatLng, or Place objects. You'll have to use the place_id to get the place details (which has the LatLng that you can use for getDistanceMatrix).

Google Maps Places API - Autocomplete city suggestions, same city, different place_ids?

I'm creating a web application with a city autocomplete suggestion field using the Google Maps Place API. Once a city is selected I capture the place_id and write it to my database attached to my object.
Currently the Google Maps Places API is returning different place_id's for the same city suggestion when searched from a different location?
The following query returns a different place_id for the result 'Brisbane, Queensland, Australia' depending on where it's searched from.
QUERY → https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Brisbane&types=(cities)&key=AIzaSyBylZrzm8TS-jfEcBgyY9Um15NCDADLt44
Searched from Brisbane: place_id = ChIJuyD2XARakWsRwITe81qjAgU
Searched from Melbourne: place_id = ChIJM9KTrJpXkWsRQK_e81qjAgQ
Similar, but different :(
I thought specifying the types parameter as '(cities)' would keep all results consistent.
Is there another parameter or change to the query that will make it bulletproof?

Google maps GeoCode API doesn't return any result at all?

This is weird. When I search something like "The New York Palace Hotel,America,New York" in Google maps app's search box I get exactly the hotel on the map.
However When I use the maps API,
A GET at http://maps.googleapis.com/maps/api/geocode/json?address=The%20New%20York%20Palace%20Hotel,America,New%20York&sensor=true
I get ZERO results in the response.
It doesn't even give New York as the option in search results.
I am making an app where I use this API to get the lat-long for user provided address.
Now, I don't know why this Google maps API doesn't work the way the Google maps app works.
BUT I wanted to know, is there a way to search and provide Google maps API these search terms as meaningful words where instead of taking whole string as one parameter it knows which city I am searching and which Address I ams searching.
If not, then only option left with me will be to Once the first results fails I make another query for city name only.
recently, i was given a similar task, and came to know the api works reverse... i.e.. we can get address for lat lon that we provide.. and that too has its own restrictions (i.e.. no.of addresses resolved per request, mostly some 2500 address per day something...)....here you can get some info over that...
You are using the Geocoding API. "The New York Palace Hotel,America,New York" is not an address, it is a "place". The Places API might be a better option.
Example of your query using the (javascript version of) the Places API

how to get an administrative_area_level_1 list for a given country from google maps api?

I'm building a drill down interactive map
I want to use lists, that will enable the user to drill from continent to country to administrative_area_level_1 regions
is there a way to query google maps api and get a list of administrative_area_level_1 names for a given country?
I looked in geocoding - which gives me essentially a lat/lng coordinates for an address
also looked at reverse geocoding, that will return address components for a given lat/lng
not relevant...
i need a list of administrative_area_level_1 names for a given country...
I don't believe Google has a complete list or API for that information, but there are several resources that might be helpful:
Counties (US Census Data)
Cities (Google AdWords API
"Geographical Targets" (Google AdWords API)
That last one is ambiguous but seems to include quite a lot. You could probably filter it down to just what you need.
Unfortunately the Google Maps API does no provide this functionality. You will have to look into solutions such as the SimpleGeo Context API.