I'm trying to find the two closest streets to a point with the Google Places API (basically to indicate the closest intersection). However, any result will only ever return one "route", if at all.
I figure I could do 5 queries in a + or X pattern, but that's hacky, unreliable, and of course will hit the query limit a lot sooner.
I am tempted to say that this is a deliberate move because the API is not meant to be used for something like navigation systems (which I'm not trying to do), but I still hope there's a TOS-compliant way to get the intersection.
Side note - it seems like specifying "types=route" never returns any results, which further nolsters my suspicion that Places is only really meant to be used for actual POIs, not for navigation, although the terms of service don't mention any explicit restrictions in that regard.
EDIT: As Chris pointed out, there's the Geocoding API that is specifically designed for geocoding, but I still don't see a way to get the closest cross street other than through multiple queries.
GeoNames provides a Geocoding API for nearest intersection from latitude/longitude coordinates.
http://www.geonames.org/maps/us-reverse-geocoder.html#findNearestIntersection
The JSON response looks like this:
{"intersection":
{"adminName2":"San Mateo",
"street2":"Curtis St",
"postalcode":"94025",
"street1":"Roble Ave",
"adminCode1":"CA",
"distance":"0.08",
"countryCode":"US",
"lng":"-122.180842",
"placename":"Menlo Park",
"lat":"37.450649",
"adminName1":"California"
},
"credits":"1.0"
}
street1
and street2
are the cross streets.
This is an old question, but I was searching for the same exact feature and Google brought me here.
Apparently is now possible to search for crossroads by simply putting an ampersand between the two street names, like
street name 1 & street name 2
this technique works for me both with the Geocoding API and the Google Maps website.
The consensus is that Google's reverse geocoder is not sophisticated enough to report intersections in one query. That is, there isn't a parameter that you can use to tell them you just want the results with "types" : [ "intersection" ]
. Google is eating its own dogfood here; if you enter a lat/lon in a maps.google search box, you always get a street (in Google parlance, a 'route') back.
As you point out, there are plenty of heuristics you could apply to get the coveted ["intersection"]
type.
e.g. Several 'major' intersections in 1st-world cities have transit stops that describe the intersection. If any results have a "types" : [ "bus_station", "transit_station" ]
element, you can try the "long_name"
element as a search term and hope you get an intersection. smirkingman also mentioned a viable solution. Both of these required 2+ queries, alas.
In conclusion, there is no latelngToIntersection(lat,lng) kind of function in the Google Geocoding API. Evidence of this exists in Google's own maps.google page. I would attack your problem differently. If you want to get the nearest major intersection given a GPS location, it may help to get the user to help. Geocoding is notoriously littered with icky humanity.
You can use data from OpenStreetMap. Their .osm
file provides the lat/long of intersecting streets.
How to get the data.
Go to OpenStreetMap and find your place where you're interested in, zoom into like the 4th tick mark.
Click Export on the top nav bar, on the drop down, press "OpenStreetMap XML Data" and click 'Export'.
For a lots of data like a state or country, Planet.osm
and find a your desired "extract".
To get the intersections, you want to look for data that matches this format, probably search for highway.
Example:
<way id="6419265" user="eric22" uid="160949" visible="true" version="2" changeset="10632563" timestamp="2012-02-09T10:49:21Z">
<nd ref="53167978"/>
<nd ref="53163978"/>
<nd ref="53163979"/>
<nd ref="53173508"/>
<nd ref="53164158"/>
<nd ref="53173510"/>
<tag <b>k="highway"</b> v="residential"/>
<tag k="name" v="Alberta St"/>
<tag k="tiger:cfcc" v="A41"/>
<tag k="tiger:county" v="St. Louis-City, MO"/>
...
</way>
The way.id is the street id, an the nd refs are streets ids can you should find in the same file. They look something like this
‹node id="53167978" lat="38.5852785" lon="-90.2450074" user="eric22" uid="160949" visible="true" version="3" changeset="10632563" timestamp="2012-02-09T10:48:49Z"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With