ciao a tutti, ho questa funzione che permette di calcolare la direzione dei marker sulla mappa, solo che calcola in base all'indirizzo io invece vorrei che funzionasse in base alle coordinate, mentre la funzione di streetview lavora perfettamente con le coordinate
posto il codice di entrambe le funzioni,
codice:
function showDirections(toAddress) {
var ddFrame = document.createElement('div');
ddFrame.setAttribute('id', 'ddFrame');
mapDiv.appendChild(ddFrame);
centerBox("ddFrame", "map");
ddBoxDiv = document.createElement('div');
ddBoxDiv.setAttribute('id', 'ddBox');
ddFrame.appendChild(ddBoxDiv);
ddBoxDiv.style.position = "absolute";
ddBoxDiv.style.left = "5px";
var ddBoxClose = document.createElement('a');
ddBoxClose.setAttribute('id', 'ddBoxClose');
ddFrame.appendChild(ddBoxClose);
ddBoxClose.style.position = "absolute";
ddBoxClose.style.zIndex = "10";
ddBoxClose.style.top = "0px";
ddBoxClose.style.left = (ddFrame.offsetWidth - ddBoxClose.offsetWidth - 4) + "px";
ddBoxClose.onclick = function() {
closeDirections();
};
var ddBoxPrint = document.createElement('a');
ddBoxPrint.setAttribute('id', 'ddBoxPrint');
ddFrame.appendChild(ddBoxPrint);
ddBoxPrint.innerHTML = "<span>Stampa</span>";
ddBoxPrint.style.position = "absolute";
ddBoxPrint.style.zIndex = "10";
ddBoxPrint.style.top = "4px";
ddBoxPrint.style.left = (ddFrame.offsetWidth - ddBoxClose.offsetWidth - 29) + "px";
ddBoxPrint.setAttribute("href", "print/print.html?start=" + escape(startAddress) + "&end=" + escape(toAddress));
ddBoxPrint.setAttribute("target", "_blank");
directionsDisplay.setMap(null);
directionsDisplay.setMap(map);
directionsDisplay.setPanel(ddBoxDiv);
var loadStr = "from: " + startAddress + " to: " + toAddress;
var request = {
origin: startAddress ,
destination: toAddress , // i wanna change toAddress with lat,lng of my marker clicked
travelMode: travMode
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
return false;
} else {
handleDDErrors();
return false;
}
});
}
streetView
codice:
function showStreetView(lat, lng, address1, address2) {
var svFrame = document.createElement('div');
svFrame.setAttribute('id', 'svFrame');
mapDiv.appendChild(svFrame);
centerBox("svFrame", "map");
var svBoxDiv = document.createElement('div');
svBoxDiv.setAttribute('id', 'svBox');
svFrame.appendChild(svBoxDiv);
svBoxDiv.style.position = "absolute";
var svBoxClose = document.createElement('a');
svBoxClose.setAttribute('id', 'svBoxClose');
svFrame.appendChild(svBoxClose);
svBoxClose.style.position = "absolute";
svBoxClose.style.zIndex = "10";
svBoxClose.style.top = "0px";
svBoxClose.style.left = (svFrame.offsetWidth - svBoxClose.offsetWidth - 5) + "px";
svBoxClose.onclick = function() {
closeStreetView();
};
var svLatLng = new google.maps.LatLng(parseFloat(lat), parseFloat(lng));
var panoramaOptions = {
position: svLatLng
};
var panorama = new google.maps.StreetViewPanorama(document.getElementById("svBox"), panoramaOptions);
map.setStreetView(panorama);
var streetViewAvailable;
var streetViewCheck = new google.maps.StreetViewService();
streetViewCheck.getPanoramaByLocation(svLatLng, 50, function(result, status) {
if (status == "OK") {
streetViewAvailable = 0;
}else{
closeStreetView();
alert("Street View unavailable for this location");
}
controlToggle("hide");
});
}
ho provato a passare alla funzione le var (lat, lng) ma non funziona, avete qualche consiglio.
grazie