Ayuda con la creación de Markers

144 views
Skip to first unread message

Juan Carlos Vargas

unread,
Apr 6, 2011, 7:58:59 PM4/6/11
to Google Maps JavaScript API v3
Buenas,

estoy intentando montar un ejemplo sencillo con Marcadores dentro de
un mapa.
Despues de leer bastante y probar de todo, deduje que lo que estaba
haciendo mal es que mezclaba partes de la V 2 y de la V 3. Una vez
decantado por usar la V 3 no encuentro ningún ejemplo claro de como se
crean marcadores mandando los datos (latitud y longitud) por Php.

Mi código es el siguiente:

<html>
<head>
<link rel="STYLESHEET" type="text/css" href="style.css">
<script type="text/javascript" src="http://maps.google.com/maps/api/js?
sensor=true"></script>
<script type="text/javascript">

var latlng;
var myOptions ;
var map;

function createMarker(lat, long) {

alert('Create Marker');
var myLatlng = new google.maps.LatLng(lat, long);
var marker = new google.maps.Marker({
position: myLatlng,
map: map
});
}

function initialize()
{
alert('Initialize');
latlng = new google.maps.LatLng(40.15, -3.25);
myOptions = { zoom: 6, center: latlng, mapTypeId:
google.maps.MapTypeId. ROADMAP };
map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var myLatlng = new google.maps.LatLng(40.15, -3.25);
var marker = new google.maps.Marker({
position: myLatlng,
map: map
});
}
</script>
</head>
<body onLoad="initialize()">
<?php
$conexion = mysql_connect('localhost','root')or die(mysql_error());
mysql_select_db('Embalses');
$resultado = mysql_query("CALL LocalizaEmbalses()")or
die(mysql_error());
while($FILA = mysql_fetch_assoc($resultado)){
?>
<script language="javascript">createMarker(<?php echo
$FILA["LATITUD"]; ?>, <?php echo $FILA["LONGITUD"]; ?>)</script>
<?php
}
?>
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>

Por favor ayudenme, no se que estoy haciendo mal y llevo 3 días sin
salir de este punto.

Muchisimas gracias

Luke Mahé

unread,
Apr 6, 2011, 8:23:55 PM4/6/11
to google-map...@googlegroups.com, Juan Carlos Vargas
This code won't work:
myLatlng = new google.maps.LatLng var (lat, long); 

instead you want:
var myLatlng = new google.maps.LatLng(lat, long); 

And this won't work:
var = new google.maps.LatLng myLatlng (40.15, -3.25); 

instead you want:
var myLatLng = new google.maps.LatLng(40.15, -3.25); 

-- Luke



2011/4/7 Juan Carlos Vargas <jcvarg...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.


Reply all
Reply to author
Forward
0 new messages