2010-09-15 7 views
0

Je suis en train d'afficher un tableau de codes postaux sur une carte Google en utilisant PHP et en utilisant le framework Symfony (1,0)afficher plusieurs marqueurs GoogleMap sur la carte

Le principal problème que j'ai, est qu'il ya un texte associé à chaque marqueur, c'est-à-dire lorsque vous cliquez sur le marqueur, une fenêtre apparaît.

Le principal problème est que le texte doit pointer vers le code postal/marqueur correct sur la carte, mais pour une raison quelconque, cela ne semble pas être le cas:

<?php 
$addresses = array(); 
foreach($contents->getResults() as $content): 
    $addresses[] = array(
     'postcode'=>sprintf('%s',str_replace(' ','',$content->getPostalCode())), 
     'html'=>escape_javascript(get_partial('property/propertyList',array('content'=>$content))), 
    ); 
endforeach; 
?> 

<?php 
echo javascript_tag(" 
var map; 
var localSearch = new GlocalSearch(); 
var center = false; 
var icon = new GIcon(); 
icon.image = 'http://www.google.com/mapfiles/marker.png'; 
icon.shadow = 'http://www.google.com/mapfiles/shadow50.png'; 
icon.iconSize = new GSize(20, 34); 
icon.shadowSize = new GSize(37, 34); 
icon.iconAnchor = new GPoint(10, 34); 
var delay = 100; 
var bounds = new GLatLngBounds(); 

var addresses = ".json_encode($addresses)."; 

var nextAddress = 0; 

function theNext() { 
    if (nextAddress < addresses.length) { 
     var postcode = addresses[nextAddress].postcode;; 
     var html = addresses[nextAddress].html 

     setTimeout('getAddress(\"'+postcode+'\",\"'+html+'\",theNext)', delay); 
     nextAddress++; 
    } 
} 
function getAddress(search, html, next) { 
    usePointFromPostcode(search, html); 
    next(); 
} 

var geoCount = 0; 
function usePointFromPostcode(address, html, callbackFunction) { 
    localSearch.setSearchCompleteCallback(null, 
     function() { 
      if (localSearch.results[0]) 
      { 
       geoCount++; 

       var resultLat = localSearch.results[0].lat; 
       var resultLng = localSearch.results[0].lng; 
       var point = new GLatLng(resultLat,resultLng); 

       var marker = new GMarker(point); 
       GEvent.addListener(marker, 'click', function() { 
        marker.openInfoWindowHtml(html); 
       }); 
       map.addOverlay(marker); 
       bounds.extend(point); 

       if(geoCount == addresses.length) { 
        setCenterToBounds(); 
       } 
      }else{ 
       //console.info('Postcode not found!', address); 
      } 
     }); 

    localSearch.execute(address + ', UK'); 
} 

function placeMarkerAtPoint(point, html) 
{ 
    var marker = new GMarker(point,icon); 
    map.addOverlay(marker); 
} 

function setCenterToBounds() 
{ 
    map.setCenter(bounds.getCenter()); 
    map.setZoom(map.getBoundsZoomLevel(bounds)); 
    console.info('zoom',map.getBoundsZoomLevel(bounds)); 
} 

function mapLoad() { 
    if (GBrowserIsCompatible()) { 
     map = new GMap2(document.getElementById('map')); 

     map.addControl(new GLargeMapControl()); 
     map.addControl(new GMapTypeControl()); 
     theNext(); 
    } 

} 

function addLoadEvent(func) { 
    var oldonload = window.onload; 
    if (typeof window.onload != 'function') { 
    window.onload = func; 
    } else { 
    window.onload = function() { 
     oldonload(); 
     func(); 
    } 
    } 
} 

function addUnLoadEvent(func) { 
    var oldonunload = window.onunload; 
    if (typeof window.onunload != 'function') { 
     window.onunload = func; 
    } else { 
     window.onunload = function() { 
     oldonunload(); 
     func(); 
     } 
    } 
} 
addLoadEvent(mapLoad); 
addUnLoadEvent(GUnload); 
") 
?> 

Il arrive que sur certains les marqueurs cependant. C'est comme si elle trouve le code postal, met le marqueur, mais affiche ensuite les mauvais détails pour cela

Répondre

0

Ok, donc il semble que les données revenant de Google, semblaient revenir dans le mauvais ordre.

Modification du délai var = 100 à retard var = 200 semblait résoudre ce

Même si elle a fait la carte charger un peu plus lent

Questions connexes