0

I would like to ask a simple question: I have a simple code in jsfiddle (in Javascript) about nearest service. More specifically, you put the coordinates and it returns the nearest coordinates to road (through Google Maps) with nearest service OSRM. This means "snap to road". How can I save theese coordinates into variables? I tried this but it doesn't work.

JavaScript in JSFiddle:

const url = '//router.project-osrm.org/nearest/v1/driving/';
const coord = {
    lon: 23.694516,
    lat: 38.017791
};

fetch(url + coord.lon + ',' + coord.lat).then(function(response) { 
    return response.json();
}).then(function(json) {
    if (json.code === 'Ok') {
        console.info(json);
        var lon=json.waypoints[0].location[0];
        var lat=json.waypoints[1].location[1];
        console.info(lat);
    }
});
plamut
  • 3,085
  • 10
  • 29
  • 40
Irini K.
  • 77
  • 1
  • 8

0 Answers0