C
According to Google, If you shorten the search a little and try to find a route between https://www.google.com.br/maps/dir/Bel%C3%A9m,+PA/Macap%C3%A1,+AP/@-0.7100566,-50.3421895,9z/data=!3m1!4b1!4m13!4m12!1m5!1m1!1s0x92a461af84756ce1:0x570d540215864c35!2m2!1d-48.4901799!2d-1.4557549!1m5!1m1!1s0x8d61e5e06b4b1a37:0x56357df330df0f97!2m2!1d-51.070535!2d0.0355735?hl=pt-BR , will see that Google shows only a plane route.I don't know if there's any swings to cross the Amazon River, but if there's Google unaware (like me, rsrsr).If you understand well, https://www.google.com.br/maps/dir/Ilha+de+Santana+-+AP/Macap%C3%A1,+AP/@-0.0175396,-51.1894615,12z/data=!4m13!4m12!1m5!1m1!1s0x929e1b4636bb1f9d:0x803f6925da1096f5!2m2!1d-51.1679643!2d-0.0706528!1m5!1m1!1s0x8d61e5e06b4b1a37:0x56357df330df0f97!2m2!1d-51.070535!2d0.0355735?hl=pt-BR . And look that google shows that they are only 15KM away. (I don't know if there's anything there, kkkk)Like you said https://pt.stackoverflow.com/questions/166136/api-google-matrix/166152?noredirect=1#comment341826_166152 that wanted only the site script and that would adapt to PHP, the site script indicated is this: <script type="text/javascript">
var map;
var geocoder;
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var path = new google.maps.Polyline();
var pageLoaded = false;
function setLatLngByInput(origem, destino) {
if (origem == "" || destino == "") {
$(".div_info").hide("slow");
return false;
}
//apaga o mapa
path.setMap(null);
directionsDisplay.setMap(null);
//declara as variaveis locais
var start;
var end;
//obtem a latitude de origem e de destino
geocoder.geocode({'address': origem}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
start = results[0].geometry.location;
gOrigemlat = results[0].geometry.location.lat();
gOrigemlng = results[0].geometry.location.lng();
geocoder.geocode({'address': destino}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
end = results[0].geometry.location;
gDestinolat = results[0].geometry.location.lat();
gDestinolng = results[0].geometry.location.lng();
//Calcula a rota
var request = {
origin: start,
destination: end,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
var distanciaRuta = response.routes[0].legs[0].distance.text;
$("#distanciarota").html(distanciaRuta);
var tiempo = response.routes[0].legs[0].duration.text;
$("#tempoviajem").html(tiempo);
directionsDisplay.setDirections(response);
directionsDisplay.setMap(map);
}
});
//Calcula a linha
dist = Math.round(((google.maps.geometry.spherical.computeDistanceBetween(start, end, 6378137)) / 1000) * 100) / 100;
$("#kmlinhareta").html(dist);
var route =
[
start, end
];
path = new google.maps.Polyline(
{
path: route,
strokeColor: "#00711D",
strokeOpacity: 0.5,
strokeWeight: 3,
geodesic: false
});
path.setMap(map);
$(".div_info").show("slow");
if (pageLoaded)
$('html, body').animate({scrollTop: $("#gotomapa").offset().top}, 2500);
else
pageLoaded = true;
} else {
alert('não foi possível encontrar o destino!');
$(".div_info").hide("slow");
return false;
}
});
}
else {
alert('não foi possível encontrar a origem!');
$(".div_info").hide("slow");
return false;
}
});
}
function setRout() {
//obtem a string de origem e de destino
var origem = $("#origem").val();
var destino = $("#destino").val();
setLatLngByInput(origem, destino);
}
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
geocoder = new google.maps.Geocoder();
var mapOptions = {
center: new google.maps.LatLng(-18.388765859930732, -49.114726562499975),
zoom: 4,
scrollwheel: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
directionsDisplay.setMap(map);
var adUnitDiv = document.createElement('div');
var adUnitOptions = {format: google.maps.adsense.AdFormat.LEADERBOARD, position: google.maps.ControlPosition.BOTTOM_CENTER, publisherId: 'ca-pub-9874183828883904', map: map, visible: true};
var adUnit = new google.maps.adsense.AdUnit(adUnitDiv, adUnitOptions);
setLatLngByInput($("#origem").val(), $("#destino").val());
var origem = document.getElementById('origem');
var fromAutocomplete = new google.maps.places.Autocomplete(origem);
var destino = document.getElementById('destino');
var toAutocomplete = new google.maps.places.Autocomplete(destino);
}
function recalcOnLoadPage() {
var fieldOrigem = $("#origem").val();
var fieldDestino = $("#destino").val();
var issetOrigem = fieldOrigem != "";
var issetDestino = fieldDestino != "";
var preenchido = issetOrigem && issetDestino;
if (preenchido) {
if ($("#distanciarota").val() == "")
setRout();
} else {
return false;
}
}
$(document).ready(function() {
$('#origem').keypress(function(e) {
if (e.which == 13) {
$("#destino").focus();
}
});
$('#destino').keypress(function(e) {
if (e.which == 13) {
$(".setrout").focus();
}
});
if ($("#origem").val() == "null") {
$("#origem").val("São Paulo, República Federativa do Brasil");
}
if ($("#destino").val() == "null") {
$("#destino").val("Rio de Janeiro, República Federativa do Brasil");
}
//$('html, body').animate({ scrollTop: $("#gotomapa").offset().top }, 4500);
initialize();
});
</script>
Good luck with the adaptation. However, if you really want to learn how to use the Google API, https://developers.google.com/maps/documentation/javascript/examples/distance-matrix