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
Related
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®ion=us&key=KEY
You need to specify the location of your search.
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
I would like to find all points that are within N miles of a given area.
E.g. the area is California: Find all points that are within 50 miles of the border of California (not the middle of California).
When using Google Maps the distance is calculated using 'the middle' of the given location, but I need to calculate the distance using the borders of the given location. The location could be any zip code, city or country.
Could that be done by drawing a polygon using California's coordinates on a map and calculate the distance to location B using the points of the polygon?
Is there a more elegant solution to this? Any ideas?
Thanks!
I'm not sure if I understand your requirements completely, but I will give it a try with different interpretations:
1. You want to filter own map points:
This can be done with any GIS or a own service that offers a call like my_points_in_area(bbox). Bbox means here boundingbox and is the 2x lat/lon pair describing the rectangle around your given centerpoint. If you want to be accurate and really just deliver whats within 100km, you might need to test the distance to the POIs once more, as the rectangle will also include points that are a bit more far away.
2. You want to filter OSM data:
You might use a reverse-geocoding service as Nominatim to get informations about points of interests that are within this distance: http://wiki.openstreetmap.org/wiki/Nominatim
Otherwise import the OSM data using osmosis to a PostGIS DB. AFAIK there is (currently) no DB tool for Oracle: http://wiki.openstreetmap.org/wiki/Oracle
I'm sorry if I missed your question, but then please add more details :)
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
I have a list of zipcoded in a MySQL Database together with their Latitude & Longitude data (Column names: ZipCode, Lat, Lon).
Now I have to make a search requests (search for the zipcode) to extract information from a website. When I make this search requests the results include all information within a radius of 50km of the zipcode.
Now, I don't want to make an unnessary high amount of search requests, so I would like to minimize the amount of zipcodes. So I'm looking for a way to filter all zipcodes, so that I have only the zipcodes where the distance between them is >50km.
Unfortunately I have no idea how to to it.
Can someone help me to solve this?
You may be interested in checking out the following presentation:
Geo/Spatial Search with MySQL by Alexander Rubin
The author describes how you can use the Haversine Formula in MySQL to limit your searches to a defined range. He also describes how to avoid a full table scan for such queries, using traditional indexes on the latitude and longitude columns.
You can use the google geocoding api , it allows you to get distances between 2 locations (lat/long, it also allows you to get zip from lat/long). From this you should be able to get the distance between each of your zipcodes and put them into a table, then you can do searches on just these.
Well, I see no other way then to iterate all rows on each request and filter them by calculating distance between selected zipcode and others (all of them), based on Lat & Lon.
I am using something similiar...
http://webarto.com/googlemaps
http://webarto.com/izrada-web-stranica/belgrade
PHP function for distance between two LL...
function distance($lat1, $lon1, $lat2, $lon2){
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
return round($miles * 1.609344,3);
}
I calculate it this way...
$sql = mysql_query("SELECT * FROM geoip WHERE city = '$city'");
while($row = mysql_fetch_array($sql)){
$ll = explode(",",$row["ll"]);
$x = distance(44.5428009033,18.6693992615,$ll[0],$ll[1]);
$road = intval($x+($x/3));
echo "Distance between ".$row["city"]." and Tuzla is ".$x." kilometers of airline, that's about ".$road." kilometers of road way.";
}
Daniel's link deals with selecting all the zip codes within 50km of a given latitude/longitude. Once you can do that, you can build a filtered list of zipcodes like this...
Select a zip code at random and add it to the filtered list
Delete all zip codes which lie within 50km of the selected zip code
Select a new zip code at random from the remaining zip codes, repeat until no more are left.
You know that you're only picking zip codes that are >50km from the ones already picked, and you know that once the original table is empty it must be because all zip codes lie within 50km of at least one of your selected zip codes.
That doesn't guarantee the smallest possible list of zip codes, and the size of the result will depend on the random choices. However, I think that this simple algorithm is likely to be "good enough", and that saving a few searches wouldn't justify the extra effort involved in finding a truly optimal solution.
The problem has been discussed previously here on SO with various solutions
I had a similar problem and I used this solution to find the answer. Not sure if you are using java or some other language but the logic can be used in any programming language
Geo Location API and finding user within a radius