2014-02-24 259 views
0

請,有人可以解釋我怎麼可以管理,在這裏地圖代碼,nokia.maps.map.Display listenernokia.places.search.manager.geocode方法?
我有地理編碼的標記,在地理編碼「oncomplete」中等待請求完成,然後在地圖顯示準備就緒時監聽,因此,如果它異步發生,它有時會在瀏覽器上顯示未完成的地圖,這是因爲map.zoomTo(bbox, false)未被執行。諾基亞這裏地圖地理編碼和顯示地圖

如何管理這兩個事件?

<script type="text/javascript"> 
function goPageOnLoad() { 
    container = new nokia.maps.map.Container(); 
    map = new nokia.maps.map.Display(document.getElementById('gmapcanvas'), 
    { components:[ infoBubbles, new nokia.maps.map.component.Behavior(), new 
    nokia.maps.map.component.ZoomBar(), new 
    nokia.maps.map.component.Overview(), new 
    nokia.maps.map.component.TypeSelector(), new 
    nokia.maps.map.component.ScaleBar() ] }); 
    addMarkersGeoLoc(map,container); 
} 

function addMarkersGeoLoc(map,container) { 
    countMarkerGeoLoc=1; coordinate = new 
    nokia.maps.geo.Coordinate(0, 0); startGeoCode('Via Roma 2, 16038 Santa 
    Margherita Ligure GE '); 
} 



function startGeoCode(addressStringt) { 
    nokia.places.search.manager.geoCode({ 
     searchTerm : addressString, 
     onComplete: function(data, requestStatus){ 
      if(data != null){ 
      coordinate = 
      new nokia.maps.geo.Coordinate(data.location.position.latitude, 
      data.location.position.longitude); 
      var marker = new 
      nokia.maps.map.StandardMarker(coordinate, {brush: {color: "#FF0000"}}); 
      marker.addListener(CLICK, function (evt) { 
      infoBubbles.openBubble(content, marker.coordinate); }); 
      container.objects.add(marker); 
      managersFinished++; 
      } 
      else { 
       managersFinished++; alert('Address: '+addressString+', is not 
       localizable.'); 
      } 
      if(managersFinished === countMarkerGeoLoc) { 
      map.objects.add(container); 
      map.set('zoomLevel', 14); 
      map.addListener("displayready", function() { 
        map.set('center', 
        [40.645304, 14.874063]); 
        bbox = container.getBoundingBox(); 
        if(bbox !=null){ 
        map.zoomTo(bbox, false); 
        } 
      }); 
      } 
     } 
     }); 
} 
</script> 

回答

0

最簡單的方法是開始你的地理編碼前等待displayready事件。

function goPageOnLoad() { 
    container = new nokia.maps.map.Container(); 
    map = new nokia.maps.map.Display 
.. etc... 
    map.addListener('displayready', function() { 
    addMarkersGeoLoc(map,container); 
    }, false); 

另一種方法是將有一個全球性的bbox變量和使用zoomTo()兩次 - 無論是在displayreadymanagersFinished === countMarkerGeoLoc

var bbox; 

... 

function goPageOnLoad() { 
    container = new nokia.maps.map.Container(); 
    map = new nokia.maps.map.Display 
.. etc... 
    map.addListener("displayready", function() { 
    if(bbox){map.zoomTo(bbox, false);} 
}); 


... 


if(managersFinished === countMarkerGeoLoc) { 
    map.objects.add(container); 
    bbox = container.getBoundingBox(); 
    map.zoomTo(bbox, false); 

第一或的zoomTo()功能的第二必須火到移動地圖。