I need to determine if a point falls on a road or not.
I don't believe there is a legitimate approach to do what you want with those APIs. However, you could probably do some hackerish, unrecommended trick using Google's Street View Image API, or with finer-grained control using the Google Maps API's StreetView objects.
Here's the thinking: If the Street View API returns a valid result (i.e. a panoramic street view image), then you might be in a street. If it doesn't, then you're not in a street.
There may be a challenge in identifying "true" responses with the stand-alone Street View Image API. One option would be to compare the image file size for a failed response, like this one, which has a Content-Length of 4868, to the image file size returned for a test point, such as a valid one like this, which has a Content-Length of 38701 ..any "true" response will result in an image with a significantly higher Content-Length value, because there is actual data in the image. Frankly, as long as you request same-size images (i.e. width and height), the Content-Length for a failure should always be the same. However the API could change even slightly and break this expectation. So it's risky.
The higher-grained control provided by the actual Google Maps JavaScript API's Street View objects will give you cleaner handling, as the google.maps.StreetViewStatus
will return one of three values and resolve this condition: OK
, UNKNOWN_ERROR
, and ZERO_RESULTS
, removing the fragile guess work necessary if you used the static image API, described previously.
But this approach is dirty. First, I think street view returns more than just near-street imagery. I'm thinking of trails in parks, user-uploaded panoramas, etc. Second, the Street View API seems to use sloshy "snapping" tolerances (like, 50 meters). In other words, if your point is close-enough, it'll give you the benefit of the doubt and return a nearby street view panorama anyway. In other words, beware false positives.
If you're considering pursuing this approach, here's an example of an endpoint that works:
http://maps.googleapis.com/maps/api/streetview?size=600x300&location=34.055526,-81.008087
And here's one that fails..
http://maps.googleapis.com/maps/api/streetview?size=600x300&location=34.05637,-81.00583
As an afterword, I don't recommend actually using this approach if the requirements of your app were defined by cast-iron business needs. But if it's just for fun and games, perhaps it's close enough?
If you want to get serious about this, you'd really need to get into PostGRESql and its PostGIS extension, and you'd need a super-detailed set of street centerlines. Open Street Map data could get you started, but be warned the quality of that data is variable ..amazing in some places ..less than in others.