I want to input source and destination and then show a direction between source and destination receptively, But the problem is google.maps.LatLng()
this function is not taking in a variable as a parameter.
if I pass value it's working
for example:
google.maps.LatLng(35.653341, -97.470570)
................................................
I have tried changing data type of var d
for example:
var d=document.getElementById("destlat").value;
it didn't work
I have also tried
google.maps.LatLng('arr[a]', 'arr[b]');
it is not working too
function initMap() {
alert("WELCOME");
var a=document.getElementById("sourcelon").value;
var b=document.getElementById("sourcelat").value;
var c=document.getElementById("destlon").value;
var d=document.getElementById("destlat").value;
var arr=[a,b,c,d,];
alert(arr);
var pointA = new google.maps.LatLng(arr[a], arr[b]);
var pointB = new google.maps.LatLng(arr[c], arr[d]);
var myOptions = {
zoom: 7,
center: pointA
},
map = new google.maps.Map(document.getElementById('map-canvas'), myOptions),
// Instantiate a directions service.
directionsService = new google.maps.DirectionsService,
directionsDisplay = new google.maps.DirectionsRenderer({
map: map
}),
markerA = new google.maps.Marker({
position: pointA,
title: "point A",
label: "Source",
map: map
}),
markerB = new google.maps.Marker({
position: pointB,
title: "point B",
label: "Destination",
map: map
});
I want to pass longitude and latitude dynamically to function but it is not working