Google Nearby places search - google-maps

I was wondering if we could get nearby location by giving the radius parameter around a fixed point. Say i want to get nearby locations only in 10km diameter of a particular location.
Can i do this using google api? or
i have to use some thing else for this?

from: http://code.google.com/apis/maps/documentation/places/
"Certain parameters are required to initiate a Place Search request. As is standard in URLs, all parameters are separated using the ampersand (&) character. The list of parameters and their possible values are enumerated below.
-location (required) — The latitude/longitude around which to retrieve Place information. This must be provided as a google.maps.LatLng object.
-radius (required) — The distance (in meters) within which to return Place results. The recommended best practice is to set radius based on the accuracy of the location signal as given by the location sensor. Note that setting a radius biases results to the indicated area, but may not fully restrict results to the specified area.

You have 2 aptions to search
1) Nearby search returns complete information of each place but it returns up to 20 results on each query and if more places available, it returns a "next page" token.
url="https://maps.googleapis.com/maps/api/place/nearbysearch/json?location="+lat+","+long+"&radius=" +radius+"&types=" + types + "&key=<PUT_YOUR_API_KEY_HERE>";
lat and long are your center coordinates.
radius is measured in meters and is a value up to 50000.
types is the type of Place you are searching according to this listing: https://developers.google.com/places/supported_types . Example: "atm"
2) Radar search that returns a reduced set of information of each place but it returns up to 200 on each query
url="https://maps.googleapis.com/maps/api/place/radarsearch/json?location="+lat+","+long+"&radius=" +radius+"&types=" + types + "&key=<PUT_YOUR_API_KEY_HERE>";
lat and long are your center coordinates.
radius is measured in meters and is a value up to 50000.
types is the type of Place you are searching according to this listing: https://developers.google.com/places/supported_types . Example: "atm"
You have more options to search, keyword & name appart from type.
You can have your results on xml or json format.
Full definition of nearby and radar search is here: https://developers.google.com/places/web-service/search

Related

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 Place Search does not return result

I need to fetch location data based on given text.
As example if I search Aldi in google map it shows me lot of data with pagination. I need to get that result using google places api.
I tried it with two API calls. But it returns me following result
https://maps.googleapis.com/maps/api/place/textsearch/json?query=Aldi&key=MY_KEY
Result
{
"html_attributions" : [],
"results" : [],
"status" : "ZERO_RESULTS"
}
https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=ALDI&inputtype=textquery&fields=place_id,name,formatted_address,geometry&key=MY_KEY
Result
{
"candidates" : [],
"status" : "ZERO_RESULTS"
}
I need to fetch data based on the given name. Can anyone find out the reason.
There are three types of searches provided by the Places API: Find Place, Nearby Search and Text Search. Each allows you to specify a location with radius to start the search from. The location is specified as a latitude/longitude pair. You received ZERO_RESULTS because you didn't specify a location for your request. If the location parameter is not specified "the API uses IP address biasing by default" according to the documentation. So, there are no Aldi stores within range of the location of your IP address.
Find Place will only return one result though, in my experience, it sometimes returns two. Both Nearby Search and Text Search will return up to 60 place results. All three of the Place search requests allow specifying a radius around your location of up to 50 kilometers. If you need to find Aldi places worldwide you'll need to make quite a few requests.
I am weeks into a similar project to find all locations for a list of restaurant chains in the US. I have found that Nearby Search is a better choice for my use case and should be considered always before committing to Text Search for a project. I've tested Aldi searches with both Nearby Search and Text Search and found that they provide the identical set of place_id results. This Nearby Search request will find all Aldi locations within 50 kilometers of New York City:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=40.785276%2C-73.9651827&name=Aldi&radius=50000&key=MY_API_KEY
Here is the same as a Text Search:
https://maps.googleapis.com/maps/api/place/textsearch/json?query=Aldi&location=40.785276%2C-73.9651827&radius=50000&key=MY_API_KEY
So why should we care? Text Search according to API documentation "... returns all of the available data fields for the selected place, and you will be billed accordingly." Furthermore "... the Text Search service is subject to a 10-times multiplier. That is, each Text Search request that you make will count as 10 requests against your quota." A Nearby Search request is less expensive and not subject to the 10x multiplier. It returns a subset of the available data fields that you might find sufficient. If you need additional data fields, you can get only what you need from a Places Detail request. Do the math for your application before you select Text Search. It might be dramatically less expensive to implement using Nearby Search followed by Places Detail requests if necessary. In any case, you don't want to be shocked when you hit quota limits unexpectedly because of the 10x multiplier OR the billed transaction costs are more than you expect!
I have found additional hurdles that should be considerations for projects attempting to find all locations for a business in a large area:
The Places API will prefer places within your radius but will include places outside your radius if it determines they are relevant and within the 60 place limit. I have had places returned more than 450 kilometers from my requested search position.
Results are going to be returned for places with names that are NOT what you searched for. In my search for the restaurant Benihana in Seattle a Nearby Search request only returns a restaurant with the name Hamansu. Upon investigation, this is because there is not a Benihana in Seattle, however, Hamansu is similar to Benihana in that it serves Japanese dishes grilled tableside. The API documentation states your search term will be "matched against all content that Google has indexed for this place, including but not limited to name, type, and address, as well as customer reviews and other third-party content."
Results are returned 20 at a time. If there are more results, a page_token is provided to make a request to get the next page of up to 20 results. Each request is chargeable. You will be billed for the 3 requests required to get 60 results. I'm not saying this is bad, just be aware of the expense and quota usage you are incurring with this API.
If there are more than 60 results for your radius then you haven't found all the possible locations within it. And, you can't determine with certainty what the effective radius covered was for the 60 results. You need to search with a small enough radius to return < 60 results for each request. A worldwide search is going to require a large quota and $ budget to pursue.
You should be aware that Places API search is not designed to provide results world wide. In your examples you specify only text value 'Aldi'. However, in order to get results you should specify also where you are searching.
For example, if I want to bias results towards Barcelona area in Spain I have to add location and radius in my request
https://maps.googleapis.com/maps/api/place/textsearch/json?query=Aldi&location=41.3850639%2C2.1734035&radius=10000&key=MY_API_KEY
This request will return Aldi supermarkets in Barcelona area as shown in my screenshot
The same thing for Find place, you should specify location bias
https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=Aldi&inputtype=textquery&fields=formatted_address,geometry,name,place_id&locationbias=circle%3A1000%4041.3850639%2C2.1734035&key=MY_API_KEY
Also note that Find place returns only one result.
I hope this addresses your doubt.
#Art answer, which is marked with higher upvotes, is only partially correct. The answer suggests that the Find Place api (e.g. maps/api/place/findplacefromtext) will usually return 1 result, at most 2. I tend to agree with him. Even if your search hits multiple targets, only one would be returned with the Find Place api. Consequently, he recommends to use Nearby Search or Text Search, both of which would yield at most 60 results.
However, these two searches require some form of location parameter, otherwise they will likely return 0 results, defaulting to using your IP address, as he indicates. But he recommends using a location accompanied with a radius parameter. The problem with this is the radius parameter has a maximum limit. So it will not target all types of things you want if you are searching over the stretch of an entire country, such as the United States.
The truth is you do not need to use the location and radius. There is another option called region. And you can use region to search the entire distance of a country.
What #Art suggested:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=25.7392%2C-80.3103&name=Law%Offices%of%Alex&radius=50000&key=KEY
https://maps.googleapis.com/maps/api/place/textsearch/json?query=Law%Offices%of%Alex&location=25.7392%2C-80.3103&radius=50000&key=KEY
A more encompassing alternative:
https://maps.googleapis.com/maps/api/place/textsearch/json?query=Law%Offices%of%Alex&region=us&key=KEY
You need to specify the location of your search.

Filter POIs that are close to a route

I have a list of Points-of-Interest (e.g. car rest areas).
The user selects the Starting Point and the Ending Point.
This generates a route.
How can I programmatically filter the POIs that are close (e.g. 50 meters distance from the road) that route?
Can Google Maps SDK or OSRM offer this functionality?
Thank you,
Nick
1. You have to find the distance from one POI to the road.
In order to accomplish this, you have to store your road in a mathematical fashion:
You can sample equidistant points of your road and store them in an array (more practical, less precise) and then calculate the distance of the POI from every point in the array, then save the minor result and repeat the whole process for every POIs.
You can store a road in a function (more and more complex, but more precise). Now that you have this function, you can calculate same distance from your POI, take the minimum value and repeat for all POIs.
2. Google Distance Matrix can actually do this
With this Api you can calculate distance till 2500 origins * destinations points.
The result will give you an array of rows, with each row corresponding
to an origin, and each element within that row corresponds to a pairing of the origin with a destination value.
Example of a request:
https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins=32.777211,35.021250&destinations=32.778663,35.015757&key=YOURAPIKEY
This is very useful to your goal, because lets you specify more than one points of which calculates distance.

Google API - Place Search - RankBy Distance

As per the google api documentation its mentioned as:
"rank results strictly by distance. In order to rank results by distance you must use some form of query or filter on the search. This can be a name filter, a type filter, or a keyword search. When results are ranked by distance it is not necessary to provide a search radius as the Places API will try to return the 20 closest results within reasonable distance"
Reference:
https://maps-apis.googleblog.com/2012/05/google-places-api-search-refinements-as.html
My question here is, what's the maximum radius/distance the API uses internally to get the matching results?
Note: For radius, the api documentation says "The maximum allowed radius is 50 000 meters". But no information about maximum/default distance the result includes is mentioned for rankBy: google.maps.places.RankBy.DISTANCE.
Any information on this will be helpful.
According to Google team the radius used with rank by distance option is 7000 meters.
Take a look at the following answer in the public issue tracker:
https://issuetracker.google.com/issues/35824648#comment2
Indeed, rankby=distance uses a default radius, currently 7000 m, and only results within that radius will be returned.

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