Google Places api - how to influence the selection for better results? - google-places-api

I'm testing Google Places API to retrieve the most popular tourist attraction in some locations. I can retrieve up to 60 results by using the pagination but in the results I get, I'm missing some major attractions while I did not reach the limit of 60 results and some minor attractions were available.
I use PHP to call the API and my API call uses the following URL structure:
https://maps.googleapis.com/maps/api/place/textsearch/json?type=tourist_attraction|point_of_interest|landmark|natural_feature|museum|amusement_park|park&language=fr&key=***myapi***&query=***location***
If I use Brussels as location, it returns only 20 results while there are way more results available for Brussels when looking for tourist attraction directly on the map. Some of the most popular attractions are not even displayed in the results. I have many similar cases for other cities/location, it's like the search was looking for results in a too narrow area.
Is there a way to get more results? Or do a kind of radius search to go around the narrow results provided by the api?
Query example:
https://maps.googleapis.com/maps/api/place/textsearch/json?type=tourist_attraction&language=fr&key=XXX&query=bruxelles
Places returned: 20
If I use pagination to get to page 2 and 3, it basically returns results that are already in the first page and I end up with 20 different places.
Places found:
Atomium,Grand-Place,Manneken Pis,Palais du Coudenberg,Parc du Cinquantenaire,Mont des Arts,Cathédrale des Sts Michel et Gudule, Bruxelles,Mini-Europe,Musée de la ville de Bruxelles,Monument du Cinquantenaire,Place Royale Bruxelles,Centre Belge de la Bande Dessinée,Parc de Bruxelles,Tour Noire,Colonne du Congrès,Tour Anneessens,Musées Royaux des Beaux-Arts de Belgique,Parc Léopold,Basilique Nationale du Sacré-Cœur à Koekelberg, Église Notre-Dame des Victoires au Sablon
There are a couple of big tourist attractions that are not in this list while I see them on Google Maps when searching for tourist attraction in Brussels.
Example:
Royal Palace (11k reviews), Train World (5k reviews), Horta Museum (2k reviews), Autoworld (7k reviews), Magritte Museum (5k reviews), St Hubert galleries (32k reviews),...
In the list of places coming from the api there are popular tourist attractions but some of them are way less popular in terms of reviews than some of the ones that are missing. They are all in the category "tourist_attraction".
So I don't understand why I only get those ones while there are many others.
Thanks
Laurent

You might get better results from Place Nearby Search, with some caveats.
Results are ranked by prominence by default: Ranking will favor prominent places within the set radius over nearby places that match but that are less prominent. Prominence can be affected by a place's ranking in Google's index, global popularity, and other factors. When prominence is specified, the radius parameter is required.
Example:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?radius=10000&type=tourist_attraction&location=50.847642,4.35717
To find the nearest results to a given location, use rankby=distance (without radius) and type=tourist_attraction (only one type).
Example: https://maps.googleapis.com/maps/api/place/nearbysearch/json?rankby=distance&type=tourist_attraction&location=50.847642,4.35717
Caveats:
This method is called Nearby Search for a reason: it only returns results that are near to the given location, if the only results that match the given type are far away they won't be returned.
The region where results are returns (search radius) is adjusted dynamically based on area density, independent of rankby parameter, so might still get less than 60 results in some places.

Related

Number of restaurants with specific cuisine in each country

I am trying to figure out how many restaurants, in each country, there are of a specific cuisine (seafood). I have looked at Google Places Api and TripAdvisor Api, but cannot find these numbers. I don´t need the list of restaurants, only number of restaurants. I found OpenStreetMap which looked very promising. I downloaded data for Norway, but the numbers are not correct (osmium tags-filter norway-latest.osm.pbf cuisine=seafood) = 62, which is way to low.
Any suggestion for how and where I can find what I am looking for?
Extrapolate.
You won't get an accurate answer, how do you even define what a seafood restaurant is?
Find out roughly how many restaurants there are in the area you are interested in and then decide what % of them might be seafood restaurants.
You can use this approach to extract the data from OpenStreetMap:
https://gis.stackexchange.com/questions/363474/aggregate-number-of-features-by-country-in-overpass
You can run the query on http://overpass-turbo.eu/ (go to settings and chose the kumi-systems server).
The query could look like this:
// Define fields for csv output
[out:csv(name, total)][timeout:2500];
//All countries
area["admin_level"=2];
// Count in each area
foreach->.regio(
// Collect all Nodes with highway=milestone in the current area
( node(area.regio)[cuisine=seafood];
way(area.regio)[cuisine=seafood];
rel(area.regio)[cuisine=seafood];);
// assemble the output
make count name = regio.set(t["name:en"]),
total = count(nodes) + count(ways) + count(relations);
out;
);
This query can take a long time (at the time of writing, mine did not yet finish)
You can also run the query via curl in on some server and let the results mailed to you via curl ....... | mail -s "Overpass Result" yourmail#example.com. You get the curl command in the browser network tab by "copy curl"
I also considered Taginfo (https://taginfo.openstreetmap.org/tags/cuisine=seafood) but it cannot filter by tag.

Algorithm for translating MLB play-by-play records into descriptive text

I'm trying to collect a dataset that could be used for automatically generating baseball articles.
I have play-by-play records of MLB games from retrosheet.org that I would like to be written out to plain text, as those that could possibly appear as part of a recap news article.
Here are some examples of the play-by-play records:
play,2,0,semim001,32,.CBFFFBBX,9/F
play,2,0,phegj001,01,FX,S7/G
play,2,0,martn003,01,CX,3/G
play,2,1,youne003,00,,NP
The following is what I would like to achieve:
For the first example
play,2,0,semim001,32,.CBFFFBBX,9/F,
I want it to be written out as something like:
"semim001 (Marcus Semien) was on three balls and two strikes in the second inning as the away player. He hit the ball into play after one called strike, one ball, three fouls, and another two balls. The fly ball was caught by the right outfielder."
The plays are formatted in the following way:
The first field is the inning, an integer starting at 1.
The second field is either 0 (for visiting team) or 1 (for home team).
The third field is the Retrosheet player id of the player at the plate.
The fourth field is the count on the batter when this particular event (play) occurred. Most Retrosheet games do not have this information, and in such cases, "??" appears in this field.
The fifth field is of variable length and contains all pitches to this batter in this plate appearance and is described below. If pitches are unknown, this field is left empty, nothing is between the commas.
The sixth field describes the play or event that occurred.
Explanations for all the symbols in the fifth and sixth field can be found on this Retrosheet page.
With Python 3, I've been able to format all the info of invariable length into a formatted sentence, which is all but the last two fields. I'm having difficulty in thinking of an efficient way to unparse (correct me if this is the wrong term to use here) the fifth and sixth fields, the pitches and the events that occurred, due to their variable length and wide variety of things that can occur.
I think I could write out all the rules based on the info on the Retrosheet website, but I'm looking for suggestions for a smarter way to do this. I wrote natural language processing as tags, hoping this could be a trivial problem in that field. Any pointers will be greatly appreciated!

Strange results from Google places autocomplete for sequence of repeating letters

This call https://maps.googleapis.com/maps/api/place/autocomplete/xml?input=qqqqqqq (plus your key) returns addresses like 'qqqqqqqqqq, Florida, USA' and 'qqqqqqqqqqqqqqqqqqqqqqqq - Luizote de Freitas, Uberlândia - State of Minas Gerais, Brazil'. I understand that QQQ might be a valid name, but qqqqqqqqqqqqqqqqqqqqqqqq? And it works the same way for any sequence of repeating letters or numbers.
Ok, let's say this is google having bad data. But how to explain results for 'www': 'Best Buy, Middlesex Turnpike, Burlington, MA, USA', 'Acton Toyota of Littleton, Great Road, Littleton, MA, USA'? I do not see any sane correlation between 'www' and the results.
You can see similar behaviour in google maps, so it's not just autocomplete API.
Any theories?
When I execute request https://maps.googleapis.com/maps/api/place/autocomplete/json?input=www&key=MY_API_KEY from my location I get really weird predictions as well
Montpellier, France (place ID ChIJsZ3dJQevthIRAuiUKHRWh60, type locality)
Berlin, Germany (place ID ChIJAVkDPzdOqEcRcDteW0YgIQQ, type locality)
Hamburg, Germany (place ID ChIJuRMYfoNhsUcRoDrWe_I9JgQ, type locality)
Munich, Germany (place ID ChIJ2V-Mo_l1nkcRfZixfUq4DAE, type locality)
Vienna, Austria (place ID ChIJn8o2UZ4HbUcRRluiUYrlwv0, type locality)
Note all of them have locality type, and indeed it smells like a bug, because I cannot see how on earth the text 'www' might match these predictions. Apparently, something is broken on Google backend and leads to the strange behavior in places autocomplete.
I can confirm that I can see this problem on Google Maps web site as well
At this point I believe the best option for us is sending a feedback to Google Maps team and hope they will fix it soon.

How to get google places api to return nearby hotels

I'm trying to put together a google places call to do a nearby search just for hotels. I tried using the types parm but the closest type to hotel I found was lodging which produced no results. So then I tried using the name parm and the same zero result. Am I missing something or is places not meant to perform a search of this type. I increased the radius to a number I'm certain that there are other hotels (2 should have been fine).
//maps.googleapis.com/maps/api/place/nearbysearch/json?location=32.800870,-96.830803&radius=25&name=Marriot%20Sheraton%20W&key=
Result from call:
{
html_attributions: [ ],
results: [ ],
status: "ZERO_RESULTS"
}
Thanks!
The radius of 25m appears to be too small and the name is not a subset of any place names in the area. Were you trying to get any places with a name of Marriot, Sheraton, or W? I don't believe the implementation works that way and instead it looks for a place with "Marriot Sheraton W" in the name.
If you change radius to 400 and name to Sheraton, then you do get the nearby "Sheraton Suites Market Center Dallas".
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=32.800870,-96.830803&radius=400&name=Sheraton&key=[key]

iphone's phone number splitting algorithm?

iPhone has a pretty good telephone number splitting function, for example:
Singapore mobile: +65 9852 4135
Singapore resident line: +65 6325 6524
China mobile: +86 135-6952-3685
China resident line: +86 10-65236528
HongKong: +886 956-238-82
USA: +1 (732) 865-3286
Notice the nice features here:
- the splitting of country code, area code, and the rest is automatic;
- the delimiter is also nicely adopted to different countries, e.g. "()", "-" and space.
Note the parsing logic is doable to me, however, I don't know where to get the knowledge of most countries' telephone number format.
where could i found such knowledge, or an open source code that implemented it?
You can get similar functionality with the libphonenumber code library.
Interestingly enough, you cannot use an NSNumberFormatter for this, but you can write your own custom class for it. Just create a new class, set properties such as countryCode, areaCode and number, and then create a method that formats the number based on the countryCode.
Here's a great example: http://the-lost-beauty.blogspot.com/2010/01/locale-sensitive-phone-number.html
As an aside: a friend told me about a gigantic regular expression he had to maintain that could pick telephone numbers out of intercepted communications from hundreds of countries around the world. It was very non-trivial.
Thankfully your problem is easier, as you can just have a table with the per-country formats:
format[usa] = "+d (ddd) ddd-dddd";
format[hk] = "+ddd ddd-ddd-dd";
format[china_mobile] = "+dd ddd-dddd-dddd";
...
Then when you're printing, you simply output one digit from the phone number string in each d spot as needed. This assumes you know the country, which is a safe enough assumption for telephone devices -- pick "default" formats for the few surrounding countries.
Since some countries have different formats with different lengths you might need to store your table with additional information:
format[germany][10] = "..."
format[germany][11] = "....."

Resources