[英]Markers not placed on Google Maps API V3
我有兩個函數initialize()
和placeMarker()
現在發生的是,在initialize
方法中,每當頁面加載時都會調用它,並初始化地圖,然后將請求發送到php腳本,該腳本發送經度和緯度位置作為響應。
腳本的響應是正確的,因為我已經使用Alertbox對其進行了檢查。
當我從$.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,
});
}
嘗試
$(parsedData).each(function(j) {
placeMarker(parsedData[j]['lat'],parsedData[j]['long']);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.