Finding nearest road using Google Places API: - ruby

In the Ruby application which I'm developing, given latitude and longitude of a point, I need to find the nearest road/highway to the point.
Can someone tell me how I can go about this using Google Places API?
I have tried giving a certain radius and finding the roads using the 'types:"route"' parameter but it gives me "Zero results" as the output.

The Google Places API is not designed to return nearby geographical locations, it is designed to return a list of nearby establishments and up to two locality or political type results to to help identify the area you are performing a Place Search request for.
The functionality you are requesting would be possible with the Google Geocoding API by passing the lat, lng to the latlng parameter of the HTTP reverse geocoding request:
http://maps.googleapis.com/maps/api/geocode/json?latlng=41.66547000000001,-87.64157&sensor=false

Old question but we have an answer now. You can use Nearest Roads API by google. It does returns the closest road segment for each point.
I have implemented in one project and it does works. Although you must keep in mind that The points passed do not need to be part of a continuous path otherwise you will find next road(parallel road) which may not be important to you.

Related

How are multiple origins/destinations supposed to be used in google distance matrix?

I'm wondering about origins and destinations in distance matrix being plural. According to the documentation you can use several locations as a starting and/or finishing point.
How can several locations be one point?
Looking at other posts it seems as this is a way to find or route between locations? So then the api chooses one of the origin locations as the optimal (shortest distance?) starting point and one of the destinations as the optimal finishing point?
Further down in the documentation it is written that the response will return one row between each origin and destination.
It is written under responses and not under the documentation for origins/destinations which is the reason this question is relevant.

Is there anyway I can get all the locations inside a bounding box using google api?

I could not find anything which provides the functionality that I want online. The only thing I could think of so far is using the text_search with different location types (e.g. schools, parks, ...) I was wondering if there is an easier way for this.
I also tried using the open street map but the locations that I get are mostly roads and residential areas names.
This is not exactly possible. Generally speaking, the Google Maps APIs are not intended to be used as databases for obtaining exhaustive lists of anything.
The closest you can do is Places API Nearby Search with rankby=distance and different type values. This is limited to the nearest 60 results.

How do we get the very nearest landmark based on lat and long in google map API?

I have a Requirement based on the above question of getting very nearest Landmark of a given Latitude and Longitude in google map api v3. Would any one knows, Please share to it.
Depends on what you would call a "landmark".
The easiest way is to use the Google Places library. You'll find an introduction here, with a full example for a "search nearby":
https://developers.google.com/maps/documentation/javascript/places
You'll then need to pick the types of places which you would consider landmarks. You'll find the list of possible types here:
https://developers.google.com/places/documentation/supported_types

How to 'fall-back' to get increasingly coarser places if nothing interesting nearby

I am getting started with the Google Places API for Java/Android and JavaScript and have something running.
I would like to be able to implement a "fall-back" approach where I return results to the user sorted by distance, but if nothing interesting (place of business, airport, shopping mall, etc.) is found within a certain radius, then I would go to a coarser granularity and return street intersection, neighborhood, or city in that order. What would be best way to do this, preferably in one query?
Also, I noticed that I can specify "rankby=distance", but I cannot provide a radius, which is very inconvenient. Is there any workaround to this limitation?
The only workaround I can think of to sort by distance within a set radius, would be to manually process the returned results to see if their location falls within your specified radius. If you believe that this would be a useful feature, I would also recommend submitting a 'Places API - Feature Request' here.
A possible solution to your "fall-back" approach would be, if the a Places API Search Request returns "status" : "ZERO_RESULTS" or if no results returned fall within your desired radius, you could perform a Geocoding API Reverse Geocoding Request using the latitude and longitude from your Places API Search Request to find the closest address.

What is the proper way to use the radius parameter in the Google Places API?

I am using the Google Places API to retrieve all the POI (Places of Interest) around a the current location, it works ok but I have noticed that whatever the value of the radius is, I always get the same number of results (~ 20). As a result, if I give a radius that is too big, I don't necessarily get the nearest POIs. If I reduce the amount of the radius to be small enough, I will retrieve those nearest places again (from experimentation, I have noticed that 100 meters is a proper value) but that means that I will not get any POIs beyond 100 meters which is not quite what I want.
My question is: is there any way by which I can get all the POIs (with no limitations) within a certain radius.
Thank you!
The Google Places API always returns 20 results by design, selecting the 20 results that best fit the criteria you define in your request. The Developer's Guide / Docs don't explicitly cite that number anywhere that I have seen. I learned about the limit watching the Autocomplete Demo & Places API Demo & Discussion Video, given by Paul Saxman, a Developer Advocate at Google and Marcelo Camelo, Google's Technical Lead for the Places API.
The entire video is worth watching, but more specific to your question, if you set the playback timer at about 11:50, Marcelo Camelo is contrasting the Autocomplete tool versus the general Places API, and that's the portion of the video where he mentions the 20 result limit. He mentions 20 as the standard result count several times.
There are many other good Places API and Google Maps videos linked to that area on YouTube as well.
As mentioned on the Google Places Issue Tracker here: http://code.google.com/p/gmaps-api-issues/issues/detail?id=3425
We are restricted by our data provider licenses to enable apps to display no more than 20 places results at a time. Consequently we are not able to increase this limit at this time.
It does sound like you are however trying to return results that are closest to a specified location, this is now possible by using the 'rankby=distance' parameter instead of 'radius' in your request.
e.g.
https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&rankby=distance&types=food&name=harbour&sensor=false&key=YOUR_API_KEY
Try google.maps.places.RankBy.DISTANCE; as default is google.maps.places.RankBy.PROMINENCE;
An easy example of this is shown Here
(Chrome only)

Resources