Comunidad de diseño web y desarrollo en internet online

multiples infowindows Api G Maps

Citar            
MensajeEscrito el 25 Sep 2011 10:45 pm
Buenas, hos voy contando con el codigo,pero basicamente es eso multiples infowindows en el Api de Ggoogle Maps.

EL teea es que debo pasar un array de php a javascript y no se si me falla eso.

Código Javascript :

<script type="text/javascript">

          var contenido = new Array();
     var marca ;
     var markers=[];


//abro php
<?php

 for($i = 0; $i <$contar; $i++) {
   
   echo "contenido.push( '$nombrezona[$i]');";

        echo "infowindow = new google.maps.InfoWindow({
});";


         echo  "  marca = marker".$idzona[$i].";
                     markers.push(marca);";

//cierro php
?>

for (var i = 0; i < markers.length; i++) {

var content = contenido[i];
var marker = markers[i];

google.maps.event.addListener(marker, 'click', function () {

infowindow.setContent(content);

infowindow.open(map, this);

});

}
<script>


He cortado mucho codigo para mostrar solo el error.

La cosa parece funiconar, deberian salir 2 marcas, y al marcar sobre ellas cada una muestre un texto:$nombrezona[$i]' (que es el array sacado de mysql, probe con echos y esan los 2 puntos).
Las marcas salen, pero al marcar en cada una, sale lo mismo, lo que hay en $nombrezona[2], por lo que imagino, la sobreescribe, pero no encuentro donde...

Haber si me podeis ayudaaar.

Gracias!

Por Phyronx

41 de clabLevel



 

chrome
Citar            
MensajeEscrito el 25 Sep 2011 11:04 pm
Hos pongo el ejemplo de donde "aprendi" ha hacer multiples infowindows:


Código Javascript :

var infowindow = null;

.

.

.

/* now inside your initialise function */

infowindow = new google.maps.InfoWindow({

content: "holding..."

});

 

for (var i = 0; i < markers.length; i++) {

var marker = markers[i];

google.maps.event.addListener(marker, 'click', function () {

// where I have added .html to the marker object.

infowindow.setContent(this.html);

infowindow.open(map, this);

});

}


Como podeis ver el usa:
infowindow.setContent(this.html);

Aparte de alguna otra cosa, pero yo necesito un texto diferente para cada infowindos...

Por Phyronx

41 de clabLevel



 

chrome
Citar            
MensajeEscrito el 17 May 2013 05:57 pm
Si exactamente! mira mi codigo, aunque necesito algunas cosas adicionales lo realice asi.

Ahora ya lo tengo todo ordenado por funciones. pero esta es la logica!

Código :


function get_georeferencias(page) {

        var campana_id = "<?php echo $campana_id; ?>";

        var cobertura = "<?php echo $cobertura; ?>";

        var ciudad = document.getElementById("ciudad").value;

        var especialidad = document.getElementById("especialidad").value;

        var enfoque = document.getElementById("enfoque").value;

        var nombre = document.getElementById("nombre").value;

        if (nombre == "")
            nombre = "todos";

        var direccion = document.getElementById("direccion").value;

        if (direccion == "")
            direccion = "todos";

        document.getElementById("contenedor_imagen_buscar").style.display = "block";

        $('select#paginas').find('option').remove().end();

        $.getJSON(myURL + 'dashboard/georeferencia_establecimientos/' + page + '/' + campana_id + '/' + cobertura + '/' + ciudad + '/' + especialidad + '/' + enfoque + '/' + nombre + '/' + direccion, function(data) {

            var geos = new Array();

            document.getElementById("total_en_base").innerHTML = data.total_georeferencia;

            document.getElementById("total_mostrando").innerHTML = data.mostrando;

            for (var j = 1; j <= data.paginas; j++) {

                var selected = "";

                if (j == data.pagina_actual)
                    selected = "selected";

                $('select#paginas').append($('<option>', {
                    value: j,
                    text: j,
                    selected: selected
                }));
            }

            for (var i = 0; i < data.geo.length; i++) {

                geos[i] = new google.maps.LatLng(data.geo[i].latitud, data.geo[i].longitud);

                var posicion = new google.maps.LatLng(data.geo[i].latitud, data.geo[i].longitud);

                var marker = new google.maps.Marker(
                        {
                            position: posicion,
                            icon: myURL + 'redime.img/iconos/' + data.geo[i].icono + '.png',
                            title: data.geo[i].nombre,
                            draggable:true
                        }
                );

                marker.setMap(map);

                mostrarMensaje(marker, data.geo[i].id, data.geo[i].nombre, data.geo[i].direccion, data.geo[i].latitud, data.geo[i].longitud);

            }

            georeferencias = geos;

            function mostrarMensaje(marker, id, nombre, direccion, latitud, longitud) {

                var infowindow = new google.maps.InfoWindow({
                    content: "<div id='ventana'> RID: " + id + "<br>Establecimiento: " + nombre + "<br>Dirección: " + direccion + "\
\<form action='" + myURL + "dashboard/actualizar_establecimiento_geo/" + id + "' method='post'> <input type='hidden' name='pagina' value='<? echo uri_string(); ?>' hidden='hidden'/>  \
\<br>Latit : <input name='latitud' id='latitud_" + id + "' value='" + latitud + "'/><br> Long: <input name='longitud' id='longitud_" + id + "' value='" + longitud + "'/><br>\
\<input type='submit' value='actualizar'/> <br><button type='button' onclick='alerta(" + id + ")'> Alerta</button>\
</div>"
                });

                google.maps.event.addListener(marker, 'click', function() {
                    infowindow.open(map, marker);

                    marker.setDraggable(true);
                    
                    if (marker.getAnimation() != null) {
                        marker.setAnimation(null);
                    } else {
                        marker.setAnimation(google.maps.Animation.BOUNCE);
                    }
                });


            }

Por mslarco

0 de clabLevel



 

chrome

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.