<?php
//datos para establecer la conexion con la base de mysql.
mysql_connect('localhost','root','')or die ('Ha fallado la conexión: '.mysql_error());
mysql_select_db('prueba')or die ('Error al seleccionar la Base de Datos: '.mysql_error());
if(trim($HTTP_POST_VARS["desde"]) != "" && trim($HTTP_POST_VARS["hacia"]) != "")
{
$coordor="6.333333, -75.55";
$coorddes="6.15, -75.633333";
$tiempo=null;
// Puedes utilizar la funcion para eliminar algun caracter en especifico
//$usuario = strtolower(quitar($HTTP_POST_VARS["usuario"]));
//$password = $HTTP_POST_VARS["password"];
// o puedes convertir los a su entidad HTML aplicable con htmlentities
$origen = strtolower(htmlentities($HTTP_POST_VARS["desde"], ENT_QUOTES));
$destino = $HTTP_POST_VARS["hacia"];
if ($origen==$destino){
?>
<script language="javascript">
alert("La Ciudad de origen no puede ser la misma que la de destino.");
location.href="index.php";
</script>
<?
}
$resultor = mysql_query('SELECT id, ciudad,coordxy FROM ubicacion WHERE id=\''.$origen.'\'');
$resultdes=mysql_query('SELECT id,ciudad,coordxy FROM ubicacion WHRE id=\'' .$destino.'\'');
if($row= mysql_fetch_array($resultor) && $row1= mysql_fetch_array($restuldes)){
$cooror=$row['coordxy'];
$corddes=$row1['coordxy'];
}else {
?>
<script language="javascript">
alert("No se encuentra la ciudad en la base de datos.");
location.href="index.php";
</script>
<?
}
}
$coordor="6.333333, -75.55";
$coorddes="6.15, -75.633333";
?>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<script src="http://maps.google.com/maps?file=api&v=2.x&key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA"
type="text/javascript"></script>
<script type="text/javascript">
// Create a directions object and register a map and DIV to hold the
// resulting computed directions
//Variables para el mapa
var map;
var directionsPanel;
var directions;
var xyfrom;
var xyto;
function initialize() {
//Cargar el mapa
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(6.216667,-75.566667), 10); //Posicionado en medellin. con zoom de 10 (puede ser de 1 a 15 el zoom)
//Añadir controles...
map.addControl(new GLargeMapControl());
var mapControl = new GMapTypeControl();
map.addControl(mapControl);
//añadir las direcciones...
directionsPanel = document.getElementById("route");
directions = new GDirections(map, directionsPanel);
xyfrom=new getLatLng(<? echo ($coordor); ?>);
xyto=new getLatLng(<? echo ($coorddes); ?>);
directions.load("from: " + xyfrom + "to: " + xyto);
//añadir el tiempo...
<?
if ($tiempo==1){
}
?>
}
</script>
<body onLoad="initialize()">
<div id="map_canvas" style="width: 70%; height: 600px; float:left; border: 1px solid black;"></div>
<div id="route" style="width: 27%; height:580px; float:right; border; 1px solid black; font-size:11px;"></div>
</body>