I am using the Place Searches from the Google Places API and wanted to know how the JSON results are returned/ordered.
E.g. are the list of places returned in a random order within the results array; or are they returned in order of nearest distance to the specified location i.e. with the first result in the results array being the nearest place to the specified location?
This is determined by the rankby parameter, which lets you choose either prominence (best search result match) or distance.
More info: https://developers.google.com/maps/documentation/places/#PlaceSearchRequests
This has been added to the API, please use the 'rankby=distance' instead of 'radius' in your Place Search Request as described in the documentation here: https://developers.google.com/maps/documentation/places/#PlaceSearchRequests
Related
I have a django project which uses elasticsearch 6.5.3 to index products in a store with locations as GeoPoints. I am trying to query this index and also calculate distance between an arbitrary point, say user's location to each oh these results.
I am using elasticsearch_dsl and my code looks something like this:
search_query = search_query.script_fields(distance={
'script':{
'inline':"doc['location'].arcDistance(params.lat, params.lon)",
'params': {
'lat':user_loc.lat,
'lon':user_loc.lon
}
}
})
for result in search_query.execute():
print(result.distance)
Which gives me values that looks like:
[123456.456879123]
But I'm not sure about its units.
By using and online distance calculator in https://www.nhc.noaa.gov/gccalc.shtml,
which gives me the distance as ~123km,
It looks like value is in meters.
So:
1. Where can I find some definitive answers about its units?
Please point me to the relevant documentation for these methods.
I am also interested to know if there is a way to specify the units expected for the results in the method call.
2. Is there a better way to do this in python?
The units are those returned by the arcDistance method providing the value in your script.
The arc distance (in meters) of this geo point field from the provided lat/lon
The painless docs leave a lot to be desired (there appears to be no docs on this method in 6.5). The quote above was obtained from here: https://www.elastic.co/guide/en/elasticsearch/reference/2.3/modules-scripting.html
Additionally, they mention arcDistance caluclates meters here: https://www.elastic.co/guide/en/elasticsearch/reference/5.5/breaking_50_scripting.html
I'm not sure about the exact python API, but elasticsearch have Geo Distance Query:
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html
In: https://github.com/elastic/elasticsearch-dsl-py/issues/398 there's an example of python usage of ES API:
MyDocType.search().filter(
'geo_distance', distance='1000m', location={"lat": "40", "lon": "-74"}
)
The 'geo_distance' query is the easiest way to get a distance between two geo points indexed to elasticsearch. I thinking that you don't need to use scripting in order to achieve that.
Regarding the distance unit, as you suspected the default is meters. from:
https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#distance-units
Wherever distances need to be specified, such as the distance parameter in the Geo Distance Query), the default unit if none is specified is the meter.
I found that nearby search returns inconsistent results.
I ran this query one day (go client lib). It returned me 4 results. Given
keyword=Resorts+World+Sentosa+Equarius+8+Sentosa+Gateway&location=1.2564%2C103.8189&rankby=distance&type=lodging
https://gist.github.com/haibin/20e01d38c10d4da9275439c549a2db91
I ran this query another day (go client lib). It returned me 5 results. Given
keyword=Resorts+World+Sentosa+Equarius+8+Sentosa+Gateway&language=en&location=1.2564%2C103.8189&rankby=distance&type=lodging
https://gist.github.com/haibin/b40e4952b7fddace78d6c37a19542a40
I ran this query today (curl). It returned me 1 result. Given
keyword=Resorts%20World%20Sentosa%20Equarius%208%20Sentosa%20Gateway&language=en&location=1.2564%2C103.8189&rankby=distance&type=lodging
https://gist.github.com/haibin/a65a6d03ace05898913e306840307bdb
Any idea why?
Possibly there was a bug in google places API when using rankby=distance parameter it skips some result or search in "limited radius"
As when I ran curl with these params
https://maps.googleapis.com/maps/api/place/nearbysearch/json?key=MY_KEY&keyword=Resorts+World+Sentosa+Equarius+8+Sentosa+Gateway&location=1.2564%2C103.8189&rankby=distance&type=lodging
it returned only one result as u said.
But when i ran with radius param it returns more results as accepted
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=1.2564,103.8189&type=lodging&keyword=Resorts+World+Sentosa+Equarius+8+Sentosa+Gateway&key=MY_KEY&radius=300
You are getting more results through go lib because probably they fixed it in that or something like that
For more info you can go through these issues:
Google Places API nearby search rankby distance skipping some nearest places
http://www.itgo.me/a/3468386017980994007/google-places-api-nearby-search-rankby-distance-skipping-some-nearest-places
Hope this will help you.
It seems not all the tweets I get using filter contain the item ("health" in this case). How could I get only tweets contain this specific item? Anyone can help me?
Thanks so much in advance!!
This is the line when I use filter:
sapi.filter(locations=[-79.55, 37.883, -75.067, 39.717],track = ["health"])
Unfortunately, the Streaming API does not allow filtering by both location and terms. From the docs:
Bounding boxes do not act as filters for other filter parameters. For example track=twitter&locations=-122.75,36.8,-121.75,37.8 would match any tweets containing the term Twitter (even non-geo tweets) OR coming from the San Francisco area.
So essentially the reason you are seeing some tweets that do not contain the word "health" is because you are receiving tweets containing the word "health", OR located within your bounding box (in this case, locations=[-79.55, 37.883, -75.067, 39.717]).
You can, however, try to filter by your term(s) then parse through the tweet data for the location, or alternately filter by location then search the tweet text for your term(s). I would probably suggest the latter if location is necessary to limit the scope of your tweet consumption.
It is very easy you just need to add this line in your code.
twitterStream.filter(track=["health"])
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]
Been looking all over the place for a solution to this issue. I have a Yahoo Pipe (http://pipes.yahoo.com/pipes/pipe.info?_id=e5420863cfa494ee40e4c9be43f0e812) that I've created to pull back image content from the Bing Search API. The URL builder includes a $skip attribute that takes an integer and uses it to select the starting (index) point for the result set that the query returns.
My initial plan had been to use the math engine in the Wolfram Alpha API to generate a random number (randomInteger[1000]) that I could use to seed the $skip value each time that the pipe is run. I have an earlier version of the pipe where I was able to get the query / result steps working using either "XPath Fetch" and "Fetch Data". However, regardless of how I Fetch the result, the response returns as an attribute / value pair in a list item.Even when I use "Emit items as string" in XPath Fetch, I still get a list with a single item, when what I really want is the integer that I can plug into my $skip attribute.
I've tried everything in Pipes I can think of, and spent a lot of time online looking for an answer. Is there anyway to extract text (in this case, a number) from a single list item and then use the output as input to "wire" a text parameter in another Pipes block? Any suggestions / ideas welcome. In the meantime, I'm generating a sorta-random number by manipulating a timecode hash, but it just feels tacky :-)
Thanks!
All the sources are for repeated items. You can't have a source that just makes a single number.
I'm not really clear what you're trying to do. You want to put a random number into part of the URL string that gets an RSS feed?