Google Places API is returning inconsistent results (less than 200) - json

I am working with the Google Places API making an application that will grab place data and display it to users based on their location but I am getting some odd behaviour with the API it is as follows:
I will make a couple different requests such as:
https://maps.googleapis.com/maps/api/place/radarsearch/json?location=40.7128,-74.0059&radius=50000&type=restaurant&key=(api-key)
(This is New York City) But even with a 50km radius I get < 200 results which is the advertised max result count. There should be significantly more than 187 (my result count) restaurants within a 50km radius of that point in New York City.
I also tried this in Vancouver, BC, Canada:
https://maps.googleapis.com/maps/api/place/radarsearch/json?location=49.256639,%20-123.097963&radius=50000&type=restuarant&key=(api-key)
And I got 198 results, when I know for a fact there are thousands of restaurants in the Greater Vancouver Area. As can be seen below this is a 50 Km radius circle over Vancouver.
As my application depends on having that hard max (200) to determine if the radius needs to shrink or grow this behaviour seems out of the ordinary. I do know it used to work this way as an older application of mine was able to use the hard max to shrink/grow dynamically on calls.

Related

Google maps sum of unique road distance in given area

I would like to calculate the number of unique kilometers of roadways in my city. More generally, I wish to sum the distance of every road within a bound, for simplicity a rectangle will do.
Is this possible using the Google Maps suite of APIs? If so, how would you go about doing it? If anyone has any resources related to this type of problem, I would be interested in reading them regardless of language (or even solutions with other mapping tools).
Bonus points: A general solution to this problem that can be applied to the pre set "cities" (example) that appear in Google Maps with well defined city limits.
You can use OpenStreetMap to calculate the total road length of a specific country or geographic area. There are multiple solutions available, based on multiple similar questions already asked.
Approach 1 from Total road length in Kilometers for a country at help.openstreetmap.org:
Use the Perl script osm-length-2.pl. There is an example at a mailing list post.
Approach 2 from Actual road length of exported map at help.openstreetmap.org:
Import your data (the planet or an country or area extract) into a PostGIS database, then use the following queries proposed by Frederik Ramm:
SELECT way AS clip
INTO clipping_polygon
FROM planet_osm_polygon
WHERE boundary='administrative' AND admin_level='8' and name='My City';
SELECT name, highway, ST_INTERSECTION(way, clip)
INTO clipped_roads
FROM planet_osm_line, clipping_polygon
WHERE ST_INTERSECTS(way, clip) AND highway IS NOT NULL;
SELECT highway, SUM(ST_LENGTH(way::geography))
FROM clipped_roads
GROUP BY highway;

how to increase the number of resulting places for google-nearby-places-web-service, as i always get up to 20 places only

i only get 20 place nearby no matter i expand the range area 500, 2000, 3000 in meters just appear new places but it doesn't add to the old one replace some so always have at max of 20 place every time
i tried running the api on other devices and expanded the search area smae problem remains
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=30.050203,31.221214&radius=1500&key=SOMEKEY
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=30.050203,31.221214&radius=3000&key=SOMEKEY
expected results to have as much as places near me so i expect when i expand the search area to 3000 meters instead of 1500 to find more plcaes
BUT i always have 20 places no matter what !!
Places API Nearby Search returns up to 20 establishment results per query, regardless of the radius value you pass to it.
Using pagetoken you can get up to 60 places, split across 3 pages (3 queries).
Check out Google's documentation to learn more: https://developers.google.com/places/web-service/search#PlaceSearchPaging
Hope this helps.

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.

limit in the geolocation of multiple points in google fusion tables

I'm trying to geolocate these 27 points at the same time, in the same row. But the process returns only the first 10 points, even if in the preview they are all 27 correctly geolocated. Why? Is there a particular limit to the number of points I can locate?
<Point><coordinates>7.680237,45.064504,0.0</coordinates></Point>
<Point><coordinates>7.681675,45.061957,0.0</coordinates></Point>
<Point><coordinates>7.685044,45.060768,0.0</coordinates></Point>
<Point><coordinates>7.686482,45.06029,0.0</coordinates></Point>
<Point><coordinates>7.689443,45.05926,0.0</coordinates></Point>
<Point><coordinates>7.692157,45.060836,0.0</coordinates></Point>
<Point><coordinates>7.693799,45.062837,0.0</coordinates></Point>
<Point><coordinates>7.69352,45.06605,0.0</coordinates></Point>
<Point><coordinates>7.693316,45.065519,0.0</coordinates></Point>
<Point><coordinates>7.693723,45.065193,0.0</coordinates></Point>
<Point><coordinates>7.694796,45.069065,0.0</coordinates></Point>
<Point><coordinates>7.689893,45.072081,0.0</coordinates></Point>
<Point><coordinates>7.684025,45.075225,0.0</coordinates></Point>
<Point><coordinates>7.682716,45.075377,0.0</coordinates></Point>
<Point><coordinates>7.675881,45.078135,0.0</coordinates></Point>
<Point><coordinates>7.674809,45.076672,0.0</coordinates></Point>
<Point><coordinates>7.673264,45.074521,0.0</coordinates></Point>
<Point><coordinates>7.672727,45.073809,0.0</coordinates></Point>
<Point><coordinates>7.671729,45.072399,0.0</coordinates></Point>
<Point><coordinates>7.670302,45.071013,0.0</coordinates></Point>
<Point><coordinates>7.669648,45.070119,0.0</coordinates></Point>
<Point><coordinates>7.669197,45.068565,0.0</coordinates></Point>
<Point><coordinates>7.670592,45.06802,0.0</coordinates></Point>
<Point><coordinates>7.672427,45.067414,0.0</coordinates></Point>
<Point><coordinates>7.67557,45.065981,0.0</coordinates></Point>
<Point><coordinates>7.675592,45.06633,0.0</coordinates></Point>
<Point><coordinates>7.675892,45.064094,0.0</coordinates></Point>
The Google Maps reverse geocoder (whichever one you are using) is subject to a quota and a rate limit. If you don't check for and handle the status OVER_QUERY_LIMIT returned, you will get that behavior.
There used to be a limitation on multigeometries that only the 10 most prominent locations would show (can't find that in the documentation for FusionTables anymore though). Put each point in its own row.

Using google maps API to find average speed at a location

I am trying to get the current traffic conditions at a particular location. The GTrafficOverlay object mentioned here only provides an overlay on an existing map.
Does anyone know how I can get this data from Google using their API?
It is only theorical, but there is perhaps a way to extract those data using the distancematrix api.
Method
1)
Make a topological road network, with node and edge, something like this:
Each edge will have four attributes: [EDGE_NUMBER;EDGE_SPEED;EDGE_TIME,EDGE_LENGTH]
You can use the openstreetmap data to create this network.
At the begining each edge will have the same road speed, for example 50km/h.
You need to use only the drivelink and delete the other edges. Take also into account that some roads are oneway.
2)
Randomly chose two nodes that are not closer than 5 or 10km
Use the dijsktra shortest path algorithm to calculate the shortest path between this two nodes (the cost = EDGE_TIME). Use your topological network to do that. The output will look like:
NODE = [NODE_23,NODE_44] PATH = [EDGE_3,EDGE_130,EDGE_49,EDGE_39]
Calculate the time needed to drive between the two nodes with the distance matrix api.
Preallocate a matrix A of size N X number_of_edge filled with zero value
Preallocate a matrix B of size 1 X number_of_edge filled with zero value
In the first row of matrix A fill each column (corresponding to each edge) with the length of the edge if the corresponding edge is in the path.
[col_1,col_2,col_3,...,col_39,...,col_49,...,col_130]
[0, 0, len_3,...,len_39,...,len_49,...,len_130] %row 1
In the first row of matrix B put the time calculated with the distance matrix api.
Then select two news node that were not used in the first path and repeat the operation until that there is no node left. (so you will fill the row 2, the row 3...)
Now you can solve the linear equation system: Ax = B where speed = 1/x
Assign the new calculated speed to each edge.
3)
Iterate the point 2) until your calculated speed start to converge.
Comment
I'm not sure that the calculated speed will converge, it will be interesting to test the method.I will try to do that if I got some time.
The distance matrix api don't provide a traveling time more precise than 1 minute, that's why the distance between the pair of node need to be at least 5 or 10 or more km.
Also this method fails to respect the Google's terms of service.
Google does not make available public API for this data.
Yahoo has a feed (example) with traffic conditions -- construction, accidents, and such. A write-up on how to access it is here.
If you want actual road speeds, you will probably need to work with a commercial provider.