OSRM Street Coordinate

by Jonatas Walker

HTML

<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=fetch"></script>
<div id="result"></div>

JavaScript

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

fetch(url + coord.lon + ',' + coord.lat).then(function(response) { 
  return response.json();
}).then(function(json) {
  if (json.code === 'Ok') {
  	console.info(json);
    document.getElementById('result').innerHTML =
    	json.waypoints[0].name + '<hr>' + json.waypoints[0].location.join();
  }
});