Ver Mensaje Individual
  #14 (permalink)  
Antiguo 12/08/2010, 17:09
neroxdt
 
Fecha de Ingreso: agosto-2010
Mensajes: 1
Antigüedad: 13 años, 9 meses
Puntos: 0
Respuesta: Ayuda con google maps y base de datos

hola, segun lo que entiendo es que tienes una base de datos donde estas guardando unas coordenadas ( lat, lng ) y las kieres mostrar en google maps.

ps bueno yo tengo algo parecido no se si te sirva:

(trate de modificarlo a tus necesidades pero ojala te sirva)

//////////////// CONEXION BD ////////////////////////////

if (!($link=mysql_connect("SERVIDOR","USUARIO","CONTR ASEÑA"))) {
echo "
<div class='content' align='center'>
<table border='2' cellpadding='2'>
<tbody>
<tr style='background-color:#033; color:; font-weight:bold'>
<td><h2>Error connecting to Database.</h2></td>
</tr>
</tbody>
</table>
</div>
";
exit();
}
if (!mysql_select_db("BASEDEDATOS",$link)) {
echo "
<div class='content' align='center'>
<table border='2' cellpadding='2'>
<tbody>
<tr style='background-color:#033; color:; font-weight:bold'>
<td><h2>Error selecting to Database.</h2></td>
</tr>
</tbody>
</table>
</div>
";
exit();
}


//////////////// CONSULTA DE LAS COORDENADAS ////////////////////////////
<?php

$sqlcoor = "SELECT lat, lng FROM tabla WHERE id= '38'";

$rescoor = mysql_query($sqlcoor, $link);

while($rowcoor = mysql_fetch_array($rescoor))
{
$latlug = $rowcoor['lat'];
$lnglug = $rowcoor['lng'];
?>

<a href="javascript:coord('<?php echo $rowcoor['lat'];?>','<?php echo $rowcoor['lng'];?>','<?php echo $rowcoor['nombre'];?>')" style="color:#000">
</a>


//////////////// SCRIPT DE LAS COORDENADAS ////////////////////////////
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=tu clavee" type="text/javascript"></script>


<script type="text/javascript">
function coord(v1, v2){

var map;
var lugar;
var lat = v1;
var lon = v2;

if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));

lugar = new GLatLng(lat, lon)
map.setCenter(lugar, 17);
map.setUIToDefault();
map.setMapType(G_NORMAL_MAP);
map.addControl(new GOverviewMapControl());

// esto es para crear un icono pero si kieres no se lo pongas
var avatar = "http://localhost/web/img/foto.jpg";

map.addOverlay(createMarker(lugar, avatar));
}

function createMarker(latlng, img_url) {
// Se define el icono
var icon = new GIcon();
icon.image = img_url
icon.iconSize = new GSize(25, 25);
icon.iconAnchor = new GPoint(50, 50);
icon.infoWindowAnchor = new GPoint(25, 25);

// Se crea el marcador
var marker = new GMarker(latlng, icon);

GEvent.addListener(marker, "click", function() {

var myHtml = "<div>"+
"<fieldset>" +
"<div>" +
"<label>" +
"<img src='" + img_url + "'/>" +
"<br/><hr/>" +
"LAT: " +
lat +
"<br/><br/>" +
"LNG: " +
lon +
"<br/><br/>" +
"</label>" +
"</div>" +
"</fieldset>" +
"</div>";

map.openInfoWindowHtml(latlng, myHtml);
});

return marker;
}
}
</script>







NOTA: no le des copy paste ya que tienes que mirar tus cosas y ver que le puedes cambiar para que te funcione con lo tuyo







OTRA COSA: alguno me puede ayudar en especificar una ruta para colombia, es que hago el metodo con el GDirection pero siempre me dice que sale error porque no reconoce algo,

obiamente si a ese mismo metodo le meto coordenadas de USA o España por ejemplo si la hace. no se como hacer eso. ayudenme por favor.