How to determine if lat long coordinates are on a road with Google Maps API v2

后端 未结 2 424
我寻月下人不归
我寻月下人不归 2021-02-04 08:56

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 man

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-04 09:16

    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

提交回复
热议问题