<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Location Partner</title>
<!--styles for map elements-->
<style type="text/css">
html {
font-family: Arial, Helvetica, sans-serif;
font-size: 15px;
height: 100%;
}
body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
/*start styles for the ContextMenu*/
.context_menu {
background-color: white;
border: 1px solid gray;
}
.context_menu_item {
padding: 3px 6px;
}
.context_menu_item:hover {
background-color: #CCCCCC;
}
.context_menu_separator {
background-color: gray;
height: 1px;
margin: 0;
padding: 0;
}
/*end styles for the ContextMenu*/
#map_container {
height: 100%;
}
</style>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?v=quarterly&key=#YOURAPIKEY#&sensor=false"></script>
<script type="text/javascript">
function initMap() {
var map = new google.maps.Map(document.getElementById('map_container'), {
zoom: 4,
center: {
lat: -24.345,
lng: 134.46
} // Australia.
});
var directionsService = new google.maps.DirectionsService;
var directionsDisplay = new google.maps.DirectionsRenderer({
draggable: true,
map: map,
panel: document.getElementById('right-panel')
});
directionsDisplay.addListener('directions_changed', function() {
computeTotalDistance(directionsDisplay.getDirections());
});
displayRoute('Perth, WA', 'Sydney, NSW', directionsService,
directionsDisplay);
}
...
</html>
Capturing the location of a draggable waypoint in Google Maps API to save it in the database and load the same directions later.
Efforts to access the waypoint's location via
result.routes[0].legs[0].via_waypoints[0]
show an empty response for lat
and lng
. Same goes for result.routes[0].legs[0].via_waypoint[0].location
.
A suggestion in the code to use
result.routes[0].legs[0].via_waypoints[0].k
and result.routes[0].legs[0].via_waypoints[0].D
did not yield results. Forum discussions propose using location.wa
and location.ya
, which also failed to provide geolocation data.
Remember to replace #YOURAPIKEY#
with your Google API key in the code snippet for it to work. This example is based on Google's documentation.
Any assistance or insights on this issue would be greatly appreciated.