Get Latitude / Longitude from Address with Accuracy - google-maps

I know this question has been asked too many times but my question is more of about standard approach.
I do have following fields in my form and using all of them for concatenation and sending to the Google Maps Api for fetching address which works.
But for some address Google Maps Api gives wrong lat/long due to the values insertion. fields with values are mentioned below.
Fields :
Street Address 1 - SHOP NO 56
Location - Sector 14
State - Haryana
City - Gurgaon
Resulting Google Map Url is giving me Lat/long of Sector 56 rather than Sector 14. Almost 9 Kms Difference.
http://maps.google.com/maps/api/geocode/json?address=Shop+No+56,Sector+14,Haryana,Gurgaon,IN
Can anybody please help me in this ?
What I tried/thought
I was planning to use Only Location Field but I suspect that will not help much.

It's true, businesses are excluded from Geocoding API. If you need a location for certain business just use the Places API.
E.g.
https://maps.googleapis.com/maps/api/place/textsearch/json?query=Shop%20No%2056%2C%20Sector%2014%2C%20Haryana%2C%20Gurgaon%2C%20IN&key=YOUR_API_KEY

Related

Google maps returning two different routes

I am surprised when I am finding the directions between two locations on google maps(maps.google.co.in) one using LAT, LNG, and the other one using the google suggested name. The routes returned are different.
Origin Address - 161 Keltner Ave, Spartanburg, SC 29302, USA.
Destination latitude and longitude - 35.554627, -82.853629
Link for address to address - https://www.google.co.in/maps/dir/161+Keltner+Ave,+Spartanburg,+SC+29302,+USA/769+Champion+Drive,+Canton,+NC,+USA/#35.2324107,-82.6430623,10z/data=!3m1!4b1!4m14!4m13!1m5!1m1!1s0x88579ff345067667:0x5c96ddb575753f29!2m2!1d-81.8723738!2d34.9216748!1m5!1m1!1s0x88598319df45a533:0xe6a9cc5fe0824b95!2m2!1d-82.853377!2d35.5548676!3e0
Link for address to lat-lng - https://www.google.co.in/maps/dir/161+Keltner+Ave,+Spartanburg,+SC+29302,+USA/35.554627,+-82.853629/#35.2321726,-82.404746,9z/data=!3m1!4b1!4m12!4m11!1m5!1m1!1s0x88579ff345067667:0x5c96ddb575753f29!2m2!1d-81.8723738!2d34.9216748!1m3!2m2!1d-82.853629!2d35.554627!3e0
Why is there so much difference? Am I missing something?
I can't make out much of a difference in the two routes. This is the address to address route as I get it from your link:
This is the route I get from your address to lat/long link:
The only significant difference is the end because the lat/long isn't 100% at the address and it appears you need to take a bit of a detour in the latter case:
The measured difference is about 223 m:

Different placeID gives the same address information

Below two placeID's gives the same address.
1. EicyMDEgU291dGggTG93cnkgU3RyZWV0LCBTbXlybmEsIFROLCBVU0EiMRIvChQKEgm7_A4lPAxkiBEptR2cpqTb1xDJASoUChIJT4MxvQIMZIgRENDVZ6XiGTc
2. ChIJBbYyJDwMZIgR1TtBueaig5w
PlaceID1 was returned when the address searched using the autocomplete was " 201 South Lowry Street" and PlaceID2 was returned when the address searched using the autocomplete was " Goodwill Industries of Middle Tennessee 201 South Lowry Street".
Even though the above addresses are different, the place details API gives the same address information.
https://maps.googleapis.com/maps/api/place/details/json?place_id=EicyMDEgU291dGggTG93cnkgU3RyZWV0LCBTbXlybmEsIFROLCBVU0EiMRIvChQKEgm7_A4lPAxkiBEptR2cpqTb1xDJASoUChIJT4MxvQIMZIgRENDVZ6XiGTc&key=API_KEY
https://maps.googleapis.com/maps/api/place/details/json?place_id=ChIJBbYyJDwMZIgR1TtBueaig5w&key=API_KEY
Question :
1. Why is the same address which is of the street returned for two different placeID's?
2. The location returned by places Details API is correct but the address is of the street.
Below are few more examples where I observed same scenarios. Could you please brief on the below mentioned examples also?
PlaceID : ChIJZ2fZgcNVZIgRRY-uzGW9IBc and ChIJi15Hp8RVZIgRojWuKm_aG3M returned the same address as "2008 Memorial Boulevard Springfield Tennessee United States 37172", but the straight line distance between the two places is approximately 154 meters.
PlaceID : EiBBbm5leCBBdmVudWUsIE5hc2h2aWxsZSwgVE4sIFVTQSIuKiwKFAoSCd8ldk-TYWSIEZbufa-nQvmSEhQKEgk9kOsTMuxkiBGg2umh0Lk_fQ and ChIJ9ynrOIthZIgR-_7_cmwzeXo returned the same address as "3736, Annex Avenue Nashville Tennessee 37209" , but the straight line distance between the two places is approximately 6.92 meters.
PlaceID : ChIJTZvXpuJ7ZIgR8GqA7eDu5oY and ChIJ3ZUKweJ7ZIgRBjj8OqdMm5E returned the same address as "1777, Galleria Boulevard Franklin Tennessee 37067 " , but the straight line distance between the two places is approximately 12.24 meters.
PlaceID : EicyMDEgU291dGggTG93cnkgU3RyZWV0LCBTbXlybmEsIFROLCBVU0EiMRIvChQKEgm7_A4lPAxkiBEptR2cpqTb1xDJASoUChIJT4MxvQIMZIgRENDVZ6XiGTc and ChIJBbYyJDwMZIgR1TtBueaig5w returned the same address as "201 S Lowry St, Smyrna, TN 37167, United States " , but the straight line distance between the two places is approximately 97 meters.
Please note that it's possible for each place or feature to have similar addresses. This is why the Places API used Place IDs instead to uniquely identify the place/feature. As per this doc:
Place IDs uniquely identify a place in the Google Places database and
on Google Maps.
Below is my investigation on the addresses you have mentioned:
The place ID, ChIJZ2fZgcNVZIgRRY-uzGW9IBc, is of type, premise. As per the Address Types doc here:
Premise indicates a named location, usually a building or collection
of buildings with a common name.
If you think that a collection of building should not have the same address as the Place ID, ChIJi15Hp8RVZIgRojWuKm_aG3M, then I suggest that you report this Maps Data issue. (I'll put some more details on how to report Maps Data issues below)
The address returned for EiBBbm5leCBBdmV...iBGg2umh0Lk_fQ is an address of a route (Annex Ave, Nashville, TN 37209, USA), which is not the same as the the second Place ID's (ChIJ9ynrOIthZIgR-_7_cmwzeXo) address (3734 Annex Ave, Nashville, TN 37209, USA).
For the Item #3, what I can see is that the place ChIJTZvXpuJ7ZIgR8GqA7eDu5oY is a street_address while the other feature (ChIJ3ZUKweJ7ZIgRBjj8OqdMm5E) is a point_of_interest. These two features does not seem to be related so I believe that this is another Maps Data issue which can also be reported.
The feature, EicyMDEgU29...ENDVZ6XiGTc, on the other hand appears to be an inferred street address from a range of addresses. While the place, ChIJBbYyJDwMZIgR1TtBueaig5w, is the actual point_of_interest that's on that same street address. Note that the point of interest may close or move to a new location, but, the street address most likely won't change.
For Maps Data issues, this can be reported using the "Report a
Problem" or "Send feedback" link on the bottom right corner on
maps.google.com or in the Google Maps for Mobile Application. To learn
more, please see this guide. But for Maps Data that are added
using Google My Business, this can be modified directly by the
business owners themselves on their Google My Business account.
I hope this helps!

autocomplete to return results within a radius

In my google maps autocomplete server side query, i'm trying to return results around or near a latitude and longitude, I've tried this so far
https://maps.googleapis.com/maps/api/place/autocomplete/json?key=<<KEY>>&types=geocode&sensor=true&language=en&location=40.64131109999999%2C-73.77813909999998&strictBounds=true&radius=10&input=london
WHERE 40.64131109999999%2C-73.77813909999998 is the latitude and longitude of JFK - John F. Kennedy International Airport.
But when the search string is london, results still show. Any idea how to limit results within a certain radius / boundary or country? Thanks
Here are my findings on your URL request:
You have included strictBounds=true which is incorrect since parameters are case sensitive hence it will be omitted in the request. It should be strictbounds instead.
You also do not need the =true because adding the parameter strictbounds is enough to restrict the places returned within the defined location and radius.
The value of radius that you have included is too small (10) which may lead to ZERO_RESULTS
You may try this request instead:
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=london&location=40.64131109999999,-73.77813909999998&radius=10000&components=country:US&strictbounds&key=YOUR_API_KEY

Google places radar search with a radius greater than 50,000 meters

I'm trying to find all Panera restaurants within a 200 mile radius of a certain point.
Here is the URL I have been using so far :
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=39.52963,-119.81380&radius=321869&type=restaurant&name=panera&key=your-key-here
However, I have found out that radius has a maximum of 30 miles. Can anyone suggest a quick workaround for me?
Thanks to all in advance.
Open Google Maps and save 8-10 or more points' lat,long value to trigger your request. Then use a loop to find all places within these points. If you want more precise results, increase first trigger points for your requests.
I tried, it works.
Assume we are using php
$triggerPoints = array("lat1,long1", "lat2,long2", "lat3,long3",....);
foreeach(triggerPoints as $t){
$requestUrl = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=$t&radius=[YOUR_RADIUS_VALUE]&type=restaurant&name=panera&key=your-key-here";
$results = file_get_contents($requestUrl);
//Do what you want with response JSON data
}
Important: When you choose trigger points, those points should intersect according to your radius value. So you don't miss any restaurants
Business license with for higher usage limits.
Contact Google sales
Google place nearby search maximum 50,000 meters (31 miles) .
if you try enter more than 50,000 it not work proper.
There is another way for find all restaurants in a city.
google provide Text Search Requests
https://maps.googleapis.com/maps/api/place/textsearch/json?query=restaurants+in+Reno,NV,89501,USA&key={API_KEY}
query = keyword + in + city Name
for get city name using latitude longitude
http://maps.googleapis.com/maps/api/geocode/json?latlng=39.52963,-119.81380&sensor=true
For more information how to get city name using latitude longitude
https://developers.google.com/maps/documentation/geocoding/start?csw=1#ReverseGeocoding
for more information about how to use Text Search Requests
https://developers.google.com/places/web-service/search

Get neighbourhoods around given location

I can get to know the suburb using google maps api. I use Autocomplete getPlace() to get sublocality_level_1. I want to know the nearby sublocalities as well.
I tried nearbysearch with type="sublocality". That fetches only maximum two results per call. Fetch with radius 200m returns two sublocalities and fetch with radius 500m returns two other sublocalities.
I want to get all sublocalities around given place_id for given radius (say 5000m). Is there a way to get that?
Looks like Google Places API doesn't have support for getting the nearby suburbs. You can only get point of interests like Restaurants, Fuel Stations, etc.
You can you the getPlace() Google Places API autocomplete to get the latitude and longitude of your suburb, and use the geonames.org API for fetching the nearby suburbs/sub localities. You have the options to pass lat, lng and radius.
Here is a example GET for fetching suburbs near 13.041703, 80.251943 in 5 KM radius
http://api.geonames.org/findNearbyPlaceNameJSON?lat=13.041703&lng=80.251943&radius=5&username=demo