我有一張地圖,我試圖從數據庫中拉出標記點,然後創建一個數組,然後使用該數組繪製地圖上的每個緯度和經度點。現在我在這裏嘗試了一些東西,但是,當我測試它時,我只在地圖上看到一點,而在亞洲則是這樣,實際上經度和緯度都指向賓夕法尼亞州。我認爲它只是將所有信息打包到數組中並試圖進行繪圖,但我不確定。真的卡在這裏任何幫助,將不勝感激。從數據庫創建Ajax結果的Javascript數組
<script type="text/javascript">
$(function() {
var arraddress = new Array();
$.ajax({
url: 'http://example.com/22/www/ba.php',
data: '',
dataType: 'json',
success: function (data) {
$.each(data, function (key, val) {
var lng = val['lng'];
var lat = val['lat'];
var id = val['id'];
var state = val['state'];
arraddress[key] = lat + ":" + lng + ":" + state + ":" + id;
//Set up the map
var APIKEY = "ed24c9065bb55c1090d3d76e7ab8577e";
var cloudmade = new CM.Tiles.CloudMade.Web({
key: APIKEY
});
var map = new CM.Map('mapdiv', cloudmade);
map.setCenter(new CM.LatLng(39.9, -98.5), 4);
//Add the markers from the array
var arLen = arraddress.length;
for (var i = 0, len = arLen; i < len; ++i) {
var onMarker = arraddress[i];
var dat = arraddress[i].split(":");
var mlat = dat[0];
var mlon = dat[1];
var mName = dat[2];
var thisMarker = new CM.Marker(new CM.LatLng(mlon, mlat), {
title: state
})
map.addOverlay(thisMarker);
}
})
}
});
});
}
</script>