I'm currently working on an app with GoogleMaps API using their PlacesAutocomplete plugin to fill an input.
The problem which I encountered is that for the result types for Airports I get only establishment. I tried using establishment and geocode for parameters in the API call but with no luck. I either get only establishment or maximum transit_station in the results. The problem with transit_station is that all the train stations, airports, bus stations are marked the same.
I need a way to get the specific type for each of them, could someone help me please, maybe I'm doing something wrong.
You can see in the screenshot below the result from the API
According to the documentation, currently the types parameter of places autocomplete supports only following values:
geocode
address
establishment
(regions)
(cities)
https://developers.google.com/maps/documentation/javascript/places-autocomplete#add_autocomplete
LE: Found a workaround
In order to get the place type I used another API this time Place Details
I took the placeId from the Autocomplete request and fired a new request to the Place Details with the fields parameter set to types
https://maps.googleapis.com/maps/api/place/details/json?key=[YOUR_KEY]&placeid=ChIJRQFUJVRhRUcR-C4yT1Y4KWk&fields=type
And the result was
{
"html_attributions": [],
"result": {
"types": [
"airport",
"point_of_interest",
"establishment"
]
},
"status": "OK"
}
So by combining the two calls I was able to get even the type which in the Autocomplete was not available
The docs for the the Place Details can be found here
Related
Implemented the Places Web Service API - Place Autocomplete https://developers.google.com/places/web-service/autocomplete and works fine, but it doesn't return the Latitude and Longitude of theses places predicted!
That is the request!
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Amoeba&types=geocode&location=37.76999,-122.44696&radius=500®ions=locality&key=KEY
This is an intended behavior. According to the documentation the autocomplete response doesn't contain any location information:
https://developers.google.com/places/web-service/autocomplete#place_autocomplete_results
You have the place ID in the response, so you can execute either place details or geocoding request to get the location for the given place.
For example, in your request the first prediction has a place ID ChIJjxz0JSktaE0RJio-PNWLd60, so you can execute the following request to get coordinates:
https://maps.googleapis.com/maps/api/geocode/json?place_id=ChIJjxz0JSktaE0RJio-PNWLd60&key=YOUR_API_KEY
The response will contain required information
"geometry":{
"bounds":{
"northeast":{
"lat":50.0903542,"lng":-86.29135079999999
},
"southwest":{
"lat":50.0850891,"lng":-86.3070178
}
},
"location":{
"lat":50.0890102,"lng":-86.2987103
},
....
I can also see that the feature request was filed in Google issue tracker, but Google rejected it and marked as Infeasible:
https://issuetracker.google.com/issues/35827993
I have a database with a list of locations and I have to get the route steps, drive distance and drive time for all combinations of locations in the database.
I have the latitude and longitude stored in the database for every location.
I'm using the google directions service api to get the information.
As long as the number of records was low, I could get the results from my code within a minute using threading.
However as the number of records increased, the number of records in combination increased exponentially (trust me, this is not the issue and the number of combinations have the potential to reach 100K), thereby causing an increase in the number of requests to be made to directions api and hence the time taken for retreival.
I understand since a large number of rest connections need to be made to the directions api, network latency plays in and the time taken to retrieve the results increases.
I googled and found that some of the maps api's (for instance waypoints in the directions service api) allow you to specify more than 1 value using the pipe operator ( | ).
I attempted to do the same and retrieve information for one source multiple destinations for every rest request however I get a NOT_FOUND status returned from the directions service.
Could someone please help me figure out how to get routes and the distance and time from the same origin but multiple destinations using the directions api.
Following is a sample url and the response I received (API_KEY was removed on purpose, cannot share that):
https://maps.googleapis.com/maps/api/directions/json?key=API_KEY&origin=49.794150,-84.564514&destination=49.244978,-88.146057|49.173205,-84.756775
{
"geocoded_waypoints" : [
{},
{
"geocoder_status" : "ZERO_RESULTS"
}
],
"routes" : [],
"status" : "NOT_FOUND"
}
Directions API doesn't support multiple origins or destinations. You can specify one origin, one destination and up to 23 waypoints.
https://developers.google.com/maps/documentation/directions/intro#Waypoints
The request with waypoints looks like:
https://maps.googleapis.com/maps/api/directions/json?origin=49.794150%2C-84.564514&destination=49.173205%2C-84.756775&waypoints=49.244978%2C-88.146057&key=YOUR_API_KEY
If you would like to test your routes and see the visual representation, you can use Directions calculator:
https://directionsdebug.firebaseapp.com/?origin=49.794150%2C-84.564514&destination=49.173205%2C-84.756775&waypoints=49.244978%2C-88.146057
Hope it helps!
For the Google Geocoding API (any version), is there any way to know if the response location (coordinate - latitude and longitude) is refereed to a 'house', a 'building' or none of them?
The idea here is to 'categorize' the location.
Given a list of human readable addresses (street name, number, zip, etc) I need to categorize each one of them as 'House', 'Building' or 'None'.
Request example:
https://maps.googleapis.com/maps/api/geocode/json?address=Dieciocho%2045%2C%20Santiago%2C%20Region%20Metropolitana&key={{key}}&components=country:CL
With the example the "location_type" is "ROOFTOP" (perfect accuracy) but even thou I don't see any address_component that can give me the information I need. Am I missing something?
I have read the api documentation (https://developers.google.com/maps/documentation/geocoding/intro#GeocodingResponses) but didn't find anything helpful for the case.
Does anyone know how to achieve this result?
Thank you in advance
There is a way in the Geocoding API (and Places API) to tell whether a result is known (to Google Maps) to be a building of some sort or not.
In your example, "types" : [ "street_address" ] indicates the address is not tied to a specific building, in the API. There may actually be a building at that location in real life, it's just that the API does not know about it. So this is kinda telling you "don't know".
In the following example, "types" : [ "premise" ] the result indicates this is some kind of building... but as you can see, it's actually a cathedral:
https://maps.googleapis.com/maps/api/geocode/json?latlng=-29.903018,-71.251052
For more fine grain distinctions, Places API Text Search lets you search for pretty much everything Google Maps does, and shows more types. These don't seem like they'll be enough to tell residential houses from other buildings though, may want to file a feature request for that.
For such a purpose, use Google Places API.
From JS v3 API, snippet is like this:
var service = new google.maps.places.PlacesService(map);
service.nearbySearch({
location: new google.maps.LatLng(...),
radius: 10,
type: ['store']
}, callback);
https://developers.google.com/maps/documentation/javascript/examples/place-search
I've been trying to find specific place in Google Places API with no success. When I type "La Cucina Trattoria" in Google Maps I get three results. However, when I run this query:
https://maps.googleapis.com/maps/api/place/autocomplete/json?key=API_KEY&input=la%20cucina%20trattoria
I only get two results. So I've tested more queries with similar effectiveness:
input=la%20cucina%20trattoria%20gmbh - no results
https://maps.googleapis.com/maps/api/place/search/json?key=API_KEY&location=48.139649,11.602685&rankby=distance&keyword=cucina - place missing in results (I've put its exact location as a parameter)
location=48.139649,11.602685&rankby=distance&keyword=Neherstraße%209 - place missing in results (however, it is returning results from the same street)
My client named two random places he knows and none of them could be found in Google Places API. Is it possible that Google Places API and Google Maps operate on two different databases? Or can these places be hidden in the public API?
I've come across similar issues, but usually changing the query gave better results. Aside from reporting it, you can manually add a place:
POST https://maps.googleapis.com/maps/api/place/add/json?key=AddYourOwnKeyHere HTTP/1.1
Host: maps.googleapis.com
{
"location": {
"lat": -33.8669710,
"lng": 151.1958750
},
"accuracy": 50,
"name": "Google Shoes!",
"phone_number": "(02) 9374 4000",
"address": "48 Pirrama Road, Pyrmont, NSW 2009, Australia",
"types": ["shoe_store"],
"website": "http://www.google.com.au/",
"language": "en-AU"
}
This should allow your application to immediately see the place and potentially have it added into Google Maps.
I was unable to find La Cucina Trattoria in Places, and I tried a number of different tactics, including a Text Search (https://maps.googleapis.com/maps/api/place/textsearch/xml?query=italian restaurant on Neherstraße in munich&key=MYKEY). I'd report it to the Place API Issues tracker here: https://code.google.com/p/gmaps-api-issues/issues/list?can=2&q=apitype:PlacesAPI%20type:Defect&sort=-stars&colspec=ID%20Type%20Status%20Introduced%20Fixed%20Summary%20Internal%20Stars
Check through the extensive list of existing bugs to see if you can add your name to an existing one and speed its resolution. Here are some similar confirmed bugs:
Some queries return no results when there should be many
Bug: Sparse search results in germany
Bug: Place details request returns wrong result
I am trying to use the Google Maps API to get the latitude and longitude of a few locations. For some reason, whenever I send a place name with an apostrophe, it does not return any results.
For instance, if I send the following requests for searching Berri's Pizza Cafe I get the results mentioned below
http://maps.googleapis.com/maps/api/geocode/json?address=berri%27s+pizza+cafe&sensor=false
{"results" : [], "status" : "ZERO_RESULTS"}
And this
http://maps.google.com/maps/geo?q=Berri%27s%20Pizza%20Cafe&output=json
{
"name": "Berri's Pizza Cafe",
"Status": {
"code": 602,
"request": "geocode"
}
}
I assume this is a problem with Google Maps API (found a forum post saying this was an issue in the javascript API but was supposedly fixed there, probably not in this)
Does anyone have a workaround for this situation?
Thanks.
The issue is that you are attempting to geocode a business name; the geocoder works with postal addresses. Omitting the apostrophe doesn't get any results either (thus proving it's not the apostrophe which is the problem).
Note that the Maps geocoder is far more sophisticated and uses a variety of data sources to locate targets, including address geolocation and business name lookup.
You may be able to find the data you're looking for using the Places API (but you will need to specify the city which you are currently omitting).