Ir para conteúdo

dlucas2002

Members
  • Total de itens

    1
  • Registro em

  • Última visita

Reputação

0 Comum

Sobre dlucas2002

  1. Bom dia, estou querendo calcular a distância entre dois pontos(ponto1 e ponto2) no google maps, alguém pode me ajudar?Já tenho os dois pontos representados por marcadores e a rota, só falta a distância entre eles.Conferi a bibliografia atual do google maps sobre Distance Matrix mas ela não tem nenhum código que funcionasse pra esse meu problema específico. <!DOCTYPE html> <html> <head> <style> /* Set the size of the div element that contains the map */ #map { height: 400px; /* The height is 400 pixels */ width: 100%; /* The width is the width of the web page */ } </style> </head> <body> <div id="map"></div> <script> function initMap() { var directionsService = new google.maps.DirectionsService(); var directionsRenderer = new google.maps.DirectionsRenderer(); var ponto1 = new google.maps.LatLng(-5.577833,-36.913061);; var ponto2 = new google.maps.LatLng(-22.934894,-47.060696); var map = new google.maps.Map(document.getElementById('map'), {zoom: 4, center: ponto2}); directionsRenderer.setMap(map); var marker = new google.maps.Marker({position: ponto1, map: map}); var marker1 = new google.maps.Marker({position: ponto2, map: map}); var request = { origin: ponto1, destination: ponto2, travelMode: 'DRIVING' }; directionsService.route(request, function(result, status) { if (status == 'OK') { directionsRenderer.setDirections(result); } }); } </script> <script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB9RfaC0_ixdYkUQokkZqO93mzvLBCrvr4&callback=initMap"> </script> </body> </html>
×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.