I put in bold what I need changed in my app, I can't figure out how to make it work, using the current location of the user on the site to center the map and use as the Origin value for the Directions API, and also I have a static value as the Destination, but I want to change it to a "clicked on"
Essentially, disregard the waypoints, but I want this to load the map at the users location, enter that value as the ORIGIN and instead of having a static destination, I want the user to click, and then it would run, giving the directions from where they are to where they clicked
" `var waypts = new Array();
<!-- var directionsService; -->
<!-- var directionsDisplay; -->
var bool = false, bool1 = false;
function initMap() {
var directionsService = new google.maps.DirectionsService;
var directionsDisplay = new google.maps.DirectionsRenderer;
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 6,
center: {lat: CURRENT LOCATION, lng: CURRENT LOCATION}
});
directionsDisplay.setMap(map);
calculateAndDisplayRoute(directionsService, directionsDisplay);
}
function calculateAndDisplayRoute(directionsService, directionsDisplay) {
var locations = new Array(I have waypoints I enter here)
var channel_id = KEY;
var api_key = 'KEY';
var bin = [];
var j=0, k=0;
for(i=1; i<=locations.length; i++){
$.getJSON('http://api.thingspeak.com/channels/' + channel_id + '/field/' + i + '/last',
function(data) {
if(data > 0) {
waypts.push({
location: '' + locations[j++],
stopover: true
});
}
k++; if(k==locations.length) { show(directionsService, directionsDisplay); }
});
}
function show(directionsService, directionsDisplay){
console.log(waypts);
directionsService.route({
origin: 'NEED CURRENT VALUE',
destination: 'CLICK ON MAP',
waypoints: waypts,
optimizeWaypoints: true,
travelMode: 'DRIVING'
}, function(response, status) {
if (status === 'OK') {
//document.getElementById('waypoints').innerHTML = response.routes[0].waypoint_order;
directionsDisplay.setDirections(response);
var route = response.routes[0];
var summaryPanel = document.getElementById('directions-panel');
//summaryPanel.innerHTML = '';
// For each route, display summary information.
console.log(route);
for (var i = 0; i < route.legs.length; i++) {
var routeSegment = i + 1;
<!-- summaryPanel.innerHTML += Route.legs[i]; -->
<!-- document.getElementById("directions-panel").innerHTML= route.legs[i].start_address + '<br>'; -->
//summaryPanel.innerHTML += '<b>Route Segment: ' + routeSegment +
//'</b><br>';
//document.getElementById("ul_list").innerHTML+= '<li>'+route.legs[i].start_address +'</li>';
for (var j = 0; j < route.legs[i].steps.length; j++) {
document.getElementById("ul_list").innerHTML+= '<li>'+route.legs[i].steps[j].instructions +'</li>';
}
//document.getElementById("ul_list").innerHTML+= '<li>'+route.legs[i].end_address +'<li>';
//document.getElementById("#buttet2").innerHTML= route.legs[i].end_address + '<br>';
//summaryPanel.innerHTML += route.legs[i].distance.text + '<br><br>';
}
document.getElementById("ul_list").innerHTML+= '<li>'+route.legs[i].start_address +'</li>';
} else {
window.alert('Directions request failed due to ' + status);
}
});
bool = true;
}
</script>
</body>
</html>`