Good afternoon, dear =)
I would like to know if anyone used google map api? There is an opportunity to get the coordinates of the routes? For example, I set points, and he returns the coordinates of the road to me. How can I get there?
Good afternoon, dear =)
I would like to know if anyone used google map api? There is an opportunity to get the coordinates of the routes? For example, I set points, and he returns the coordinates of the road to me. How can I get there?
It’s not entirely clear about points - is the route target meant, or an array of points along a route?
if we are talking about laying the optimal route from one location to another, here is my code for one of the projects:
function showroute() { var directionsDisplay = new google.maps.DirectionsRenderer(); var directionsService = new google.maps.DirectionsService(); var start = document.getElementById("routefrom").value; var end = document.getElementById("routeto").value; var request = { origin:start, destination:end, travelMode: google.maps.DirectionsTravelMode.DRIVING }; directionsService.route(request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setDirections(response); var myRoute = response.routes[0].legs[0]; document.getElementById("other").innerHTML+=start+' - '+end+': <b>'+myRoute.distance.text+'</b><br>'; } }); directionsDisplay.setMap(map); }
the map object must be initialized in advance.
The starting point of the route is entered into the text field with id = route from the final one - id = routeto, the result is output to the block with id = other.
When entering points, you can use the detailing of the form: "house, street, city, district, region"
Source: https://ru.stackoverflow.com/questions/64492/
All Articles