诺基亚在这里映射地理编码和显示地图

时间:2014-02-24 10:53:32

标签: geocoding here-api

请有人解释我如何管理,在此地图代码中,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>

1 个答案:

答案 0 :(得分: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()函数的第一个或第二个必须触发才能移动地图。

相关问题