2012-05-27 5 views
0

두 개의 함수가 있습니다 initialize()placeMarker() 이제는 페이지가로드 될 때마다 initialize 메소드에서 해당 메소드가 호출되고지도가 초기화 될 때마다 요청을 PHP 스크립트로 보냅니다 이에 대한 위도 및 경도 위치마커가 Google Maps API V3에 배치되지 않았습니다

경고 상자를 사용하여 체크 한대로 스크립트의 응답이 정확합니다.

$.each 외부에서 placeMarker 함수를 호출하면 작동합니다.

그러나 내부에서 호출하면 $.each 마커를 배치하지 않습니다.

function initialize(latitude,longitude) 
{ 
    geocoder = new google.maps.Geocoder(); 

    //Initial Map Variables 
    var mymap={ 
      zoom:8, 
      center:new google.maps.LatLng(latitude,longitude), 
      mapTypeId:google.maps.MapTypeId.ROADMAP 
     }; 

     //Initialize Map 
     map=new google.maps.Map(document.getElementById("map_canvas"),mymap); 

      // placeMarker(latitude,longitude); 
      // placeMarker(latitude + 0.2,longitude + 0.2);  When these two are called it places the marker on the map 

    $.ajax({ 
      type: 'GET', 
      url: "Profile_Control.php", 
      data: "ajaxRequest=yes&id="+document.getElementById("compid").value, 
      success:function(data){ 
      var parsedData= $.parseJSON(data); 
      $.each(parsedData,function(){ 
       placeMarker(this['lat'],this['lng']);   

     //not place the marker on the map. 
      }); 
     } 
     }); 
} 


//Place the marker and update the array. 
function placeMarker(latitude,longitude) 
{ 
    var myLatLng = new google.maps.LatLng(latitude,longitude); 

      var marker = new google.maps.Marker({ 
        map: map, 
        position:myLatLng, 
       }); 
} 
+0

시도? – wong2

+0

어떻게 확인하나요? 브라우저가 정상적으로 작동하고 있습니다. – Mj1992

+0

Chrome을 사용하는 경우 Ctrl + Shift + J를 눌러 콘솔을 열고 거기에 오류가 있는지 확인하십시오. – wong2

답변

-1

주어진 오류가 브라우저 있습니까

$(parsedData).each(function(j) { 
    placeMarker(parsedData[j]['lat'],parsedData[j]['long']); 
}); 
+0

시도했지만 작동하지 않음 – Mj1992

+0

'placeMarker (parsedData [j] .lat, parsedData [j] .long); '그럼. 또한 jQuery의 어떤 버전을 사용하고 있습니까? – fanf

+0

작동하지 않습니다. 'v1.6.2'을 사용하고 있습니다. – Mj1992

관련 문제