Creating a map and adding 2 "draggable markers":
var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
var mapOptions = {
zoom: 4,
center: myLatlng
}
var map = new google.maps.Map(document.getElementById("map"), mapOptions);
// Place a draggable marker on the map
var marker1 = new google.maps.Marker({
position: myLatlng1,
map: map,
draggable:true,
title:"Marcador 1"
});
var marker2 = new google.maps.Marker({
position: myLatlng2,
map: map,
draggable:true,
title:"Marcador 2"
});
Calculate distance:
function CalcularDistancia(latlng1, latlng2) {
var service = new google.maps.DistanceMatrixService();
service.getDistanceMatrix(
{
origins: [latlng1],
destinations: [latlng2],
travelMode: google.maps.TravelMode.DRIVING // mude de acordo com seu proposito
}, callback);
}
function callback(response, status) {
if (status == google.maps.DistanceMatrixStatus.OK) {
alert("Distância:" + response.rows[0].elements[0].distance.text);
}
}
but how would I add the first pin, and then the second ? So he adds the two at once....
– Rafael Perrechil
Separate into a function and call her when you need her!
– Lucas Torres