
como puedo pasar el id de msg o el resultado de Driving distance is a una varible php urgente por fa
Publicado por stiven (8 intervenciones) el 31/08/2020 18:06:38
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html>
<head>
<style>
/* Set the size of the div element that contains the map */
#map {
height: 400px;
width: 600px;
}
</style>
</head>
<body>
<!--The div elements for the map and message -->
<div id="map"></div>
<div id="msg"></div>
<script>
// Initialize and add the map
var map;
function initMap() {
// The map, centered on Central Park
const center = {lat: 40.774102, lng: -73.971734};
const options = {zoom: 15, scaleControl: true, center: center};
map = new google.maps.Map(
document.getElementById('map'), options);
// Locations of landmarks
const dakota = {lat: 40.7767644, lng: -73.9761399};
const frick = {lat: 40.771209, lng: -73.9673991};
// The markers for The Dakota and The Frick Collection
var mk1 = new google.maps.Marker({position: dakota, map: map});
var mk2 = new google.maps.Marker({position: frick, map: map});
let directionsService = new google.maps.DirectionsService();
let directionsRenderer = new google.maps.DirectionsRenderer();
directionsRenderer.setMap(map); // Existing map object displays directions
// Create route from existing points used for markers
const route = {
origin: dakota,
destination: frick,
travelMode: 'DRIVING'
}
directionsService.route(route,
function(response, status) { // anonymous function to capture directions
if (status !== 'OK') {
window.alert('Directions request failed due to ' + status);
return;
} else {
directionsRenderer.setDirections(response); // Add route to the map
var directionsData = response.routes[0].legs[0]; // Get data about the mapped route
if (!directionsData) {
window.alert('Directions request failed');
return;
}
else {
document.getElementById('msg').innerHTML += " Driving distance is " + directionsData.distance.text + " (" + directionsData.duration.text + ").";
}
}
});
}
</script>
<!--Load the API from the specified URL -- remember to replace YOUR_API_KEY-->
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyC_pQuc0J_LufdnehFSMD0M6MB9Ni64_-8&callback=initMap">
</script>
</body>
</html>
Valora esta pregunta


0