Salve ragazzi,
sono nuovo del forum. Ho bisogno di aiuto abbastanza importante per convertire una pagina da php ad asp. la pagina serve a prelevare delle informazioni da un file xml per definire il percorso di una mappa con i vari waypoints. Vi posto il php.
<?php
$strDefaultLocationList= <<<XML
origin: "Messina, IT",
destination: "Varese, IT",
waypoints:[ {location: "Roma, IT"},
{location: "Napoli, IT"},
{location:"Firenze, IT"},
{location:"Bologna, IT"},
{location:"Parma, IT"}],
optimizeWaypoints:true,
travelMode: google.maps.DirectionsTravelMode.DRIVING
XML;
$strCleanLocationList= <<<XML
origin: "{origin}",
destination: "{destination}",
{waypoints}travelMode: google.maps.DirectionsTravelMode.DRIVING
XML;
$strOrigin="";
$strDestination="";
$strWayPoints="";
$bolValidRequest=false;
$bolValidWPRequest=false;
if(!(is_null($_GET['origin']) || is_null($_GET['destination']) )){
$bolValidRequest = strlen(trim($_GET['origin']))>0 && strlen(trim($_GET['destination']))>0;
}
if(!is_null($_GET['waypoints'])){
$bolValidWPRequest = strlen(trim($_GET['waypoints']))>0;
}
$strTmp="waypoints:[\n\t";
$strComma="";
if($bolValidRequest){
$strOrigin=trim($_GET['origin']);
$strDestination=trim($_GET['destination']);
if($bolValidWPRequest){
$arrayWP= preg_split("/\|/", trim($_GET['waypoints']));
foreach($arrayWP as $location){
$strTmp.="$strComma {location: \"$location\"}";
$strComma=",\n\t";
}
$strTmp.="], \noptimizeWaypoints:true,\n";
$strWayPoints=$strTmp;
}
$strCleanLocationList = str_replace("{origin}", $strOrigin , $strCleanLocationList);
$strCleanLocationList = str_replace("{destination}", $strDestination , $strCleanLocationList);
$strCleanLocationList = str_replace("{waypoints}", $strWayPoints , $strCleanLocationList);
$strDefaultLocationList=$strCleanLocationList;
}
?>
<!DOCTYPE html>
<html>
<head>
<link
href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
<meta http-equiv="content-type" content="text/html" ;/>
<title>truck google maps</title>
<script
src="http://maps.google.com/maps/api/js?key=AIzaSyAgCDTytfmNPtT-3jeZsvQjtQOJygsDlCU&sensor=false"
type="text/javascript"></script>
</head>
<script type="text/javascript">
var rendererOptions = {
draggable: false
};
var directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions);
var directionsService = new google.maps.DirectionsService();
var map;
var latlng = new google.maps.LatLng(38.192323, 15.555267);
function initialize() {
var myOptions = {
zoom: 16,
mapTypeId: google.maps.MapTypeId.HYBRID,
center: latlng,
};
map = new google.maps.Map(document.getElementById("map_canva s"), myOptions);
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById ("directionsPanel"));
google.maps.event.addListener(directionsDisplay, 'directions_changed', function() {
computeTotalDistance(directionsDisplay.directions) ;
});
calcRoute();
}
function calcRoute() {
var request = {<?=$strDefaultLocationList?>
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
else if (status == google.maps.DirectionsStatus.NOT_FOUND)
alert("Si � verificato un errore nella geocodifica degli indirizzi");
else if (status == google.maps.DirectionsStatus.MAX_WAYPOINTS_EXCEEDE D)
alert("La versione in uso consente l'analisi di soli 8 punti intermadi pi� partenza ed arrivo");
else alert("Si � verificato un errore");
});
}
function computeTotalDistance(result) {
var total = 0;
var myroute = result.routes[0];
for (i = 0; i < myroute.legs.length; i++) {
total += myroute.legs[i].distance.value;
}
total = total / 1000.
document.getElementById("total").innerHTML = total + " km";
}
</script>
<body onload="initialize()">
<div id="map_canvas" style="float: left; width: 70%; height: 100%"></div>
<div id="directionsPanel" style="float: right; width: 30%;">
Distanza Totale: <span id="total"></span></p>
</div>
</body>
</html>

Rispondi quotando