2011-05-16 15 views
5

Hey. I'mm tratando de poner dos puntos en un solo mapa con la misma div id ..
pero no funciona ..
código:google map dos marcadores en un mapa

para la primera,

var map = new GMap2(document.getElementById("map-canvas")); 
    map.addControl(new GLargeMapControl()); 
    map.addControl(new GMapTypeControl()); 
    map.setCenter(new GLatLng(<?=$lat;?>,<?=$lng;?>), 6); 

    var point = new GLatLng(<?=$lat;?>,<?=$lng;?>); 
    var marker = createMarker(point,'Welcome:<b></b><br>Second Info Window with an image<br><img src="http://localhost/gps/user_photo/" width=80 height=80>') 
    map.addOverlay(marker); 


    function createMarker(point,html) { 
     var marker = new GMarker(point); 
     GEvent.addListener(marker, "click", function() { 
      marker.openInfoWindowHtml(html); 
     }); 
     return marker; 
     } 

por segundo,

var map = new GMap2(document.getElementById("map-canvas")); 
    map.addControl(new GLargeMapControl()); 
    map.addControl(new GMapTypeControl()); 
    map.setCenter(new GLatLng(<?=$mylat;?>,<?=$mylng;?>), 6); 

    var point1 = new GLatLng(<?=$mylat;?>,<?=$mylng;?>); 
    var marker = createMarker1(point1,'Welcome:<b></b><br>Second Info Window with an image<br><img src="http://localhost/gps/user_photo/" width=80 height=80>') 
    map.addOverlay(marker); 


    function createMarker1(point,html) { 
     var marker = new GMarker(point); 
     GEvent.addListener(marker, "click", function() { 
      marker.openInfoWindowHtml(html); 
     }); 
     return marker; 
     } 

por qué dos puntos no se muestran en un mapa ????? y se verá en dos mapas diferentes ...

+1

¿son dos puntos de latitud diferentes? ¿por qué no usar V3 google map? ¿Por qué ambos marcadores comparten una identificación? Los Id son únicos – kjy112

+0

¿No estás creando dos mapas diferentes? – miguelSantirso

+0

no quiero eso en un mapa con este código tan – keyur

Respuesta

1
//set up map as before 

    var point0 = new GLatLng(<?=$mylat0;?>,<?=$mylng0;?>); 
    var point1 = new GLatLng(<?=$mylat1;?>,<?=$mylng1;?>); 
    var marker0 = createMarker(point0,'Welcome:<b></b><br>First Info Window etc); 
    var marker1 = createMarker(point1,'Welcome:<b></b><br>Second Info Window etc); 
    map.addOverlay(marker); 

// only declare this once 
    function createMarker(point,html) { 
     var marker = new GMarker(point); 
     GEvent.addListener(marker, "click", function() { 
      marker.openInfoWindowHtml(html); 
     }); 
     return marker; 
     } 

Esta es una manera de hacerlo sólo para conseguir que funcione para usted, pero esencialmente los puntos y js los marcadores deben ser matrices que se repiten, probablemente lo mismo que los $ mylat y $ mylong vars en PHP.

0

Según tengo entendido, quiere agregar dos puntos en un mapa, en una página. Si es así - que no es necesario para inicializar Gmap dos veces, simplemente hacer algo como esto: http://pastebin.com/BtvdfaiP

+0

pero es acero trabajando en este código: var mapDiv = document.getElementById ('map-canvas'); \t mapa = new google.maps.Map (mapDiv, { \t \t centro: new google.maps.LatLng (, ), \t \t zoom: 13, \t \t mapTypeId: google.maps.MapTypeId.ROADMAP \t}); \t \t directionsDisplay.setMap (mapa); – keyur

+0

tiene razón, pero con diferentes códigos obtuve dos puntos diferentes (lat, lng) así que – keyur

+0

no estoy seguro de entender su objetivo correctamente. ¿Puedes describirlo más claro? –

Cuestiones relacionadas