please, could someone explain me how can I manage, in Here Maps code, nokia.maps.map.Display listener and nokia.places.search.manager.geocode method?
I have markers to be geocoded, in geocode "oncomplete" it waits for the request to be completed, after that it listens when map display is ready, so as it happens asynchronously, it sometimes displays on browser a map not finished yet, this is because map.zoomTo(bbox, false) was not executed.

How can I manage these two events?

<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>
有帮助吗?

解决方案

The simplest method would be to wait for the displayready event before starting your geocoding.

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

The other alternative would be to have a global bbox variable and use zoomTo() twice - either on displayready or on managersFinished === countMarkerGeoLoc i.e.

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);

Either the first or the second of the zoomTo() functions must fire to move the map.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top