I need to make a check in my application that determines whether the given coordinates lie on road or not in Google Maps.
Is there any function in Google Maps API that can aid me with that?
Thanks in advance!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As far as I know this can’t be done using the Google Maps API.
I think your best bet is to use a crowd-sourced dataset such as OpenStreetMap (OSM).
You’d need to set up your own spatial database (e.g., PostGIS) and import OSM data into the database.
Then, you’d create a server-side API (hosted in a web server such as Tomcat or Glassfish) to receive the mobile phone’s current location, buffer the location with a certain radius to give you a circular polygon, and do a spatial query via PostGIS to determine if the buffer intersects any roads (e.g., ways with labels of “highway=primary” or “highway=secondary”, depending on what road types you want to include – see this site), and return the true or false response to the phone.
EDIT Aug 2015
There is now a method in the android-maps-utils library called
PolyUtil.isLocationOnPath()that would allow you to do this type of calculation within your Android app itself, assuming you have the set of points that make up the road (or any other line).Here’s what the code looks like in the library:
To use this library, you’ll need to add the library to your
build.gradle:Then, when you have your point and your path, you’d need to convert your lat/longs to
LatLngobjects (specifically, aLatLng pointandList<LatLng> line, respectively), and then in your code call:…to see if your point is within 10 meters of your line.
See the Getting Started Guide for this library for more info on how to use it.