13

I have used Google geo address and using lat/long have got the address. How do I determine if I am on road on not? Basically hit-test for road? I am currently using location manager for lat/long and the GeoAddress is same for on road and next to road.

JSuar
  • 21,056
  • 4
  • 39
  • 83
jason
  • 3,932
  • 11
  • 52
  • 123

2 Answers2

11

Final Solution

Use reverse geocoding via the Google Geocoding API.

The term geocoding generally refers to translating a human-readable address into a location on a map. The process of doing the converse, translating a location on the map into a human-readable address, is known as reverse geocoding.

The Geocoding API supports reverse geocoding directly using the latlng parameter. For example, the following query contains the latitude/longitude value for a location in Brooklyn:

http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true_or_false

The docs explain how to interpret the json results but StackOverflow has various answers addressing more efficient ways to parse the data.

Possible Solutions

Quick Search Results

Unsolved Similar Questions

Community
  • 1
  • 1
JSuar
  • 21,056
  • 4
  • 39
  • 83
  • @JSuar exactly as Mr.Johnson stated. – jason Jan 04 '14 at 16:58
  • Sorry about that. Updated my answer. If none of these links prove useful, I will delete my answer. Still researching, however. – JSuar Jan 04 '14 at 17:00
  • @JSuar Thanks again for your time and effort. – jason Jan 04 '14 at 17:02
  • http://econym.org.uk/gmap/example_snap.htm snaps to nearest road how does it know where the road is ? Its interesting .Can we implement the same on android google maps v2 ?Let me know any workaround.Thanks again for your time. – jason Jan 04 '14 at 17:30
  • @jason That solution relies on [loadFromWaypoints](https://developers.google.com/maps/documentation/javascript/v2/reference?csw=1#GDirections.loadFromWaypoints). [This SO question provides a solution](http://stackoverflow.com/questions/8271176/loadfromwaypoints-with-more-than-25-points-using-google-maps-api-v2) to the restrictions placed on the function. – JSuar Jan 04 '14 at 17:37
  • 40.721171, -74.011178 is the point I have clicked how do I snap to nearest road ? in other words how do I know coordinates or polylines for the nearest road ? – jason Jan 04 '14 at 17:54
  • The links in my answer and previous comment provide code examples. I'd just be reposting their code. Unless you post some of your own code, I can't suggest what exactly you need to do. – JSuar Jan 04 '14 at 18:28
  • http://maps.googleapis.com/maps/api/geocode/json?latlng=40.721171,%20-74.011178&sensor=false .How do I know which is the nearest street? or how do I point it to nearest road?Sorry for not providing more code but I have exact location w.r.t to google maps.Please let me know if you need more info. – jason Jan 04 '14 at 18:45
  • how do I snap to nearest road from here . http://maps.googleapis.com/maps/api/geocode/json?latlng=40.721171,%20-74.011178&sensor=false – jason Jan 04 '14 at 18:56
  • [This documentation](https://developers.google.com/maps/documentation/geocoding/#ReverseGeocoding) explains how to interpret and parse the results you need. I know the final pieces are fuzzy but this looks like it will solve your problem. Pretty cool that this geocoding service is available. – JSuar Jan 04 '14 at 20:46
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/44520/discussion-between-jason-and-jsuar) – jason Jan 04 '14 at 20:48
4

See fiddle.

It can be done so much easier with OSRM (nearest) webservice. Make a GET request like:

const url = '//router.project-osrm.org/nearest/v1/driving/';
fetch(url + coord.lon + ',' + coord.lat).then(function(response) { 
  return response.json();
}).then(function(json) {
  if (json.code === 'Ok') {
    console.info(json.waypoints[0].location);
  }
});

Which is a road/street coordinate.

References — Project-OSRM

Jonatas Walker
  • 13,583
  • 5
  • 53
  • 82