Question

I want to ask how can I zoom to all marker that stored in an array using JavaScript.. Thank you guys in advance.

Here is my code..

    $.each(data, function(i,val){

        outletMarkers[val.id] = new Array();

        var lat = parseFloat(val.latitude);
        var lng = parseFloat(val.longitude);

        outletMarkers[val.id] = new nokia.maps.map.StandardMarker(

            [lat,lng],
            {
                text: val.text,
                $click  : 'showBubble("'+val.text+'",'+lat+','+lng+',false,"'+val.id+'");'                }


        );

        map.objects.add(outletMarkers[val.id]); 
    });
Was it helpful?

Solution

You can to do this, to create a container, add all makers to container and zoom to map. for example:

var myContainer = new nokia.maps.map.Container();

$.each(data, function(i,val){

    outletMarkers[val.id] = new Array();

    var lat = parseFloat(val.latitude);
    var lng = parseFloat(val.longitude);

    outletMarkers[val.id] = new nokia.maps.map.StandardMarker(

        [lat,lng],
        {
            text: val.text,
            $click  : 'showBubble("'+val.text+'",'+lat+','+lng+',false,"'+val.id+'");'
        }
    );

myContainer.objects.add(outletMarkers[val.id]);// add all makers to the container });

Add the container to the map map.objects.add(myContainer);

Zoom to all makers map.zoomTo(myContainer.getBoundingBox());

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top