Getting an intersection with Google Places/Geocoding API
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.
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.