Use Google place autocomplete web service with Latitude & Longitude - google-maps

I want to use Google place autocomplete webservice: https://developers.google.com/places/web-service/autocomplete
to search for locations based upon a query (e.g. "High Street"). I also want the latitude and longitude of each place.
It seems that the only way to do this using the web service is to:
Perform an autocomplete search e.g.
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Vict&types=(cities)&language=en_GB&key=YOUR_API_KEY
Loop through each result and do a separate query for each location (see https://developers.google.com/places/web-service/details):
https://maps.googleapis.com/maps/api/place/details/json?placeid=PLACE_ID&key=YOUR_API_KEY
That means if I have 10 results, I have to do 10 additional web requests! That means 11 in total (1 for autocomplete, and 10 more for each place request).
This is very inefficient!
Surely there is a better way than this, as Google Maps on Android shows the distance of each place to your current location, indicating that the latitude and longitude is returned as shown by this screenshot:

Yes, for Places API, Directions API and Geocoding API that is the case. There is no other way.

you can use this API
of google APIs
https://maps.googleapis.com/maps/api/geocode/json?address=Winnetka&key=YOUR_API_KEY

Related

How to find municipality and postal code that are in range from coordinates?

Is there a way by using azure-maps or google-maps to get from longitude and latitude all postal codes and municipalityes that are in range of X kilometers?
I've yet checked the Get Search Nearby of azure, but it returns only points of interests and it is not possible to specify in the API a range in which the data should be get.
In Azure Maps, getting all postal code/municipalities within a specified distance of a location or within an area is not currently available. However, this is something being investigated as a possible future service. Consider submitting this as a feature request here: https://feedback.azure.com/forums/909172-azure-maps
I don't believe Google Maps has any such service either.

Google Maps Geocoding API not returning all results

I was typing "macys" as the search item in here (google maps website) which gives me around 30 to 40 results marked on the map.
Where as when I use their API with query term "macys" then it returns only 2 to 3 results. I am using the following api:
http://maps.googleapis.com/maps/api/geocode/json?address=macys&sensor=false
I am possibly using the wrong API because it says as 'address' in the query parameter. Which API should I be using for getting all macys locations in the US / World?
I want it to return all the lat and lng objects as if its done in their own website (google maps website). If they have not exposed the API then is there a way around?
You should use the Places API:
https://developers.google.com/places/documentation/
Geocoding is not designed to return POIs, it might return some, but you should not depend on it.

Google Places API returning sparse results vs Google Places iPhone app

I am building an application which uses Google Places API to show restaurants near my current location. For some reason the results are very sparse compared to the results that I can see from the Google Places iPhone application. For example from my rural home, Google Places app shows the nearest location 2.4 mi away. The Places API from this lat/long shows the nearest location 15.7 mi away.
Is it possible that "Google Places" the application is not using the Google Places API?
The Google Places App does not use the Google Places API so you will not see the exact same results, however you should see similar results.
A few tips when using the Places API:
The Places API by default sorts returned results in your selected radius by prominence, not distance. If you would like to find the closest places as it sounds like you are trying, use rankby=distance in your query with out the radius parameter.
Try using the keyword parameter instead of the 'name' parameter, as per the documentation: the 'keyword' parameter is matched against all available fields, including but not limited to name, type, and address, as well as customer reviews and other third-party content, this tends to return more results.
If you adhere to these tips you will most likely get similar results to Places App.

Get latitude / longitude / Reverse Geocoding without displaying maps

Using a website, I am trying to capture user's latitude / longitude point and based on that grab his current address.
I am able to do this using Google Maps API: geolocation and Reverse GeoCoding. But, my requirement is to get this information without displaying the map. As far as I have read, Google Maps Term of Use prohibits such thing.
Can anyone let me know if there is any other service which can serve my purpose without displaying maps or does Google Maps allow such thing? I am not sure about Bing, Yahoo.
EDIT: On page load, I need to grab user's latitude and longitude and based on that get address information. I am planning to use this address information for displaying nearby locations/places to visit. I have to achieve this without displaying any map.
Yahoo PlaceFinder does it. If you pass through the latitude and longitude in the location parameter and gflags=R, it should return address data.
You'll have to get a Yahoo APP id, but its free and pretty easy to set up.
EDIT: I see you want to do geolocation too, if you can't use google I would investigate html5 geolocation and or use freegeoip.net to geolocate by ip address.
I don't know if Im mistaken this post, but if you read this:
(viii) store or allow end users to store map imagery, map data or geocoded location information from the Yahoo! Maps APIs for any future use;
(ix) use the stand-alone geocoder for any use other than displaying Yahoo! Maps or displaying points on Yahoo! Maps;
It's mean that you can't store the information, or make use of it, without maps.
So the google api and the yahoo api need to have a map...
note- I take that lines from the terms of yahoo: http://info.yahoo.com/legal/us/yahoo/maps/mapsapi/mapsapi-2141.html
EDIT - Now I'm trying to use http://www.geonames.org/export/reverse-geocoding.html It's easy, and works fine for me. I just need the city and maybe a postal code.
I don't think Yahoo requires you to show a map and it also has a higher quota.
http://developer.yahoo.com/geo/placefinder/
There are a number of geolocation APIs - here is a really good one:
https://geoip.nekudo.com/
You merely make a GET request to
http://geoip.nekudo.com/api/{ip}/{language}/{type}
where ip, language and type are optional.
E.g. in Angular 5, using HttpClient:
this.http.get('http://geoip.nekudo.com/api/')
.subscribe(
data => { console.log('SUCCESS! Your coords are lat:', data.location.latitude, 'long:', data.location.longitude); },
error => { console.log('ERROR!', error); }
);
Also, note that the geoip service is written in PHP and open source (https://github.com/nekudo/shiny_geoip) so you can house your own implementation to reduce third party dependencies.

How to handle inaccurate Google Maps locations?

When I type in addresses in Google maps for locations in Asia, quite a lot of them are off by more than 200 metres. For example, "blk 85 bedok north road, singapore" is off by more than 300 metres. While I don't expect Google Maps to be spot on every time, sometimes the error is too great for certain use cases. What options do I have to handle inaccurate Google Maps locations in a web app? The web app should let the user enter an address or postal code as part of an entry and I will geocode the address and store the lat-long.
You could use bing, yahoo's and google's Geo Location api's to find latitude and longitude for a location, average the results together and use the result. Thus, if they all agree, you still get a good location, but if they disagree you get the best approximation of all three.
You could even programmatically compare the results from each engine and throw out any that don't agree with the others (for instance, if bing and yahoo agree and google does not, you could throw out google).
Beyond that, if you have a collection of addresses you know to be wrong, you could simply store the correct longitude and latitude for those points, and override the results in those cases.
Of course, to get around this problem at all, you'll need to geocode the addresses, check their validity in some way (as described above), and plot them using their latitude and longitude.
You don't have any fixes for this really, you're at the mercy of the accuracy of google maps here. The important part is you don't know if the address in inaccurate when doing one search to the next, so nothing you can do to handle it.
You can post a topic here and google will see it and often respond as well: Google Maps Local Listing Forums. I'd open something there with some of your examples and hope they get more accurate...that's all you can do in this case.
There are always other alternatives as well, yahoo and bing have mapping APIs, but I have no idea how much better or worse off you'd be going that route.
The problem is not the lat/lng data, in fact, they are correct. The problem is that the geo coords of the map tiles of the public Google maps api are inaccurate. The maps at maps.google.com are provided by a different map provider than the map tiles used with the public Google Maps API that you can embed in your website, use in your own applications, etc.
Check my recent posting at Google Maps & apps with mapview have different current positions
Is the result out on maps.google.com as well as through the maps api?
If on google maps live site the result is accurate then you can do an ajax search to return the correct lon/lat.
I have used this when geocoding UK postcodes
Geocoding UK Postcodes with Google Map API
I tried to reply to the upper answer, but I am not qualified enough yet. Just be aware that whatever you're using for geocoding, sometimes has restrictions on the use of that data. For example, google's geocoding API isn't allowed to be used to display information retrieved anywhere but google maps. The same might be for the others, I don't know what your project is, but it's something to be aware of.