2012-02-16 2 views
0

이 JSON-P 콜백에서 반복 된 각 마커는 (앞에서 선언 한) bounds이라는 객체를 확장하려고합니다. 로그에서, 그것은 경계 객체로 설정 얻을 않지만, NE SW는 동일합니다 :이 경계 개체가 확장되지 않는 이유는 무엇입니까?

ie $: de b: 18.031393699999967 d: 18.031393699999967 __proto__: de Y: he b: 59.2933167 d: 59.2933167 __proto__: he __proto__: ie

왜? 이 날 미치게됩니다 ..

addStoreMarkers: function(data) { 
      /** This is the function that the injected script automatically calls, it passes the markers data in the form 
       JSON (an array object) as an argument. **/ 

       //iterate over each instance in the data 
       for (var i in data.markers) { 

        //set marker icon 
        var image = new google.maps.MarkerImage('images/'+ data.markers[i].icon +'.png', 
         new google.maps.Size(32.0, 37.0), 
         new google.maps.Point(0, 0), 
         new google.maps.Point(16.0, 37.0) 
        ); 

        //set icon shadow 
        var shadow = new google.maps.MarkerImage('images/shadow.png', 
         new google.maps.Size(51.0, 37.0), 
         new google.maps.Point(0, 0), 
         new google.maps.Point(16.0, 35.0) 
        ); 

        //add markers to map 
        var marker = new google.maps.Marker({ 
         position: new google.maps.LatLng(data.markers[i].lat, data.markers[i].lgt), 
         map: map, 
         visible: false, 
         icon: image, 
         shadow: shadow 
        }); 

        //add marker to markers array 
        markers.push(marker); 

        //create the bounds representing all downloaded markers 
        bounds = new google.maps.LatLngBounds(); 
        bounds.extend(marker.position); 

        //store infoBox data in markers array 
        markers[i].store = data.markers[i].store; 
        markers[i].distance = data.markers[i].distance; 
        markers[i].i = i; 

        //add click-listener to marker 
        google.maps.event.addListener(markers[i], 'click', function() { 
         //on click 
          //set parameter active (so it won't hide) 
          Map.setMarkerActive(this); 
          //call todisplay custom infoWindow function 
          Map.displayInfo(this); 
        }); 

       } 

       console.log(bounds); 

       //fitbounds if requested, else pan a bit to call updateView 
       if(first){Map.fitBounds(5);first=false;} else {map.panBy(1,1);} 

       //remove data from the DOM 
       ejectDOM('#jsonp_ref'); 

       //notify 
       Menu.setStatus('Klart!'); 

       //housekeeping 
       delete data; 

       console.log('add markers function complete ' + markers.length); 
     }, 

답변

1
//create the bounds representing all downloaded markers 
bounds = new google.maps.LatLngBounds(); 
bounds.extend(marker.position); 

당신은 각 마커에 대한 새로운 경계를 만들 수 있습니다. for 루프 바깥쪽에 경계를 만들어야합니다.

+0

나는 그것을 보지 못했다고는 믿을 수 없다. .. – jenswirf

관련 문제