【发布时间】:2014-06-04 00:11:40
【问题描述】:
我需要数组中的图标,比较后取一个图标数组,作为通过JSON获取数据,因此无法将它们作为对象告诉他们。
创建图标并将它们放在数组中:
EMarkers = [];
var icon1e = {
nameIco: icon1e,
url: "./icon/sight.png",
size: new google.maps.Size(16, 16),
anchor: new google.maps.Point(8, 8),
};
EMarkers.push(icon1e);
var icon2e = {
nameIco: icon2e,
url: "./icon/museum21.png",
size: new google.maps.Size(16, 16),
anchor: new google.maps.Point(8, 8),
};
EMarkers.push(icon2e);
var icon3e = {
nameIco: icon3e,
url: "./icon/hram.png",
size: new google.maps.Size(16, 16),
anchor: new google.maps.Point(8, 8),
};
EMarkers.push(icon3e);
但是对象Icon中的自定义选项不会传输,还有marker。
jQuery.getJSON(url, function (json) {
jQuery.each(json, function(i, entry){
var _id = entry.event_id;
var _point = new google.maps.LatLng(entry.options.lat,entry.options.lng);
jQuery.each(EMarkers, function(idx, data){
if (data.nameIco == entry.options.icon){
entry.options.icon = data;
}
});
createMarker( _point, entry.options);
});
});
function createMarker(point, options){
var marker = new google.maps.Marker({
position: point,
map: map,
icon: options.icon,
title: options.title,
id: options.id
});
}
问题是我无法将 JSON 图标仅用作字符串作为标记,这是我能看到的从数组创建对象的唯一方法,但如何从中获得所需的值?
【问题讨论】:
标签: javascript json google-maps icons google-maps-markers