我在創建Google地圖中的標記時遇到問題。在列表中爲每個經緯度創建一個標記谷歌地圖
我有一個函數在JS是讓長串
locationlist看起來像: 「[{」 緯度 「:」 34.163291" , 「LNG」: 「 - 118.685123」},{」緯度 「:」 38.91992" , 「LNG」: 「 - 76.992757」},{ 「緯度」: 「39.309265」, 「LNG」: 「 - 76.749287」},{ 「緯度」: 「40.658113」, 「LNG」:」 -74.005874 「},{」 緯度 「:」 33.837814" , 「LNG」: 「 - 117.886568」}]」 ...... (長串)
對於每個緯度,經度在這個字符串我想創建一個標記並將其顯示在地圖上 希望有人能幫助我那個。
它也會影響地圖加載的速度嗎?當一次加載一堆標記!
JS Funcation:
var locationObj;
var historyObj;
function setMap(locationList) {
// List of Lat,Lng
locationObj = $.parseJSON(locationList);
//Looping through the Object
for (i in locationObj) {
var LatLngPair = new google.maps.LatLng(locationObj[i]["Lat"], locationObj[i]["Lng"]);
// Getting the Lat,Lng frmo the object
var hItem = locationObj[i];
var qLat = parseFloat(hItem["Lat"]);
var qLong = parseFloat(hItem["Lng"]);
var qMapTypeId = google.maps.MapTypeId.SATELLITE
var myLatlng;
if (qLat != 0 && qLong != 0) {
myLatlng = new google.maps.LatLng(qLat, qLong);
mapOptions = {
zoom: 1,
center: myLatlng,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
}
}
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
map.setTilt(45);
map.setHeading(0);
map.setMapTypeId(qMapTypeId);
var marker = new google.maps.Marker({
position: myLatlng,
map: map
});
google.maps.event.addListener(marker, "click", function (event) {
});
}
}
$("#map-canvas").show();
$("#divLoadingMessageMap").css("display", "none");
}
我修改了代碼,但地圖上把它永遠載入和它」被困住了。 – 2014-11-20 23:17:08
你是否得到一個特定的錯誤? – plondon 2014-11-20 23:21:42
沒有錯誤,但地圖花費太長的時間來加載 – 2014-11-20 23:25:19