我有一个数组:
var data = new Array();
data[0] = new Array();
data[0][0] = 'First_loc';
data[0][1] = '36.91781,36.63568';
data[1] = new Array();
data[1][0] = 'Second_loc';
data[1][1] = '36.88827,36.636908';
在我初始化谷歌地图之后
var overlay;
function initialize() {
var myLatLng = new google.maps.LatLng(36.88827, 36.636908);
var mapOptions = {
zoom: 9,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var gmap = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
for (var i = 0; i < data.length; i++) {
var name_1 = data[i][0];
var loc = data[i][1];
function HTMLMarker() {
this.pos = new google.maps.LatLng(loc);
}
HTMLMarker.prototype = new google.maps.OverlayView();
HTMLMarker.prototype.onRemove = function () {}
//init your html element here
HTMLMarker.prototype.onAdd = function () {
div = document.createElement('DIV');
div.className = "htmlMarker";
div.data = "data-price";
div.innerHTML = '<a href="#' + name_1 + '" class="pin_on_map"></a>';
var panes = this.getPanes();
panes.overlayImage.appendChild(div);
}
HTMLMarker.prototype.draw = function () {
var overlayProjection = this.getProjection();
var position = overlayProjection.fromLatLngToDivPixel(this.pos);
var panes = this.getPanes();
panes.overlayImage.style.left = position.x - 30 + 'px';
panes.overlayImage.style.top = position.y - 48 + 'px';
}
//to use it
var htmlMarker = new HTMLMarker(loc);
htmlMarker.setMap(gmap);
}
}
现在我正在循环函数(这并不好)并且我得到了最后一个值,所以我在地图上有两个具有相同值的引脚。如果有人知道解决方案吗?所以在循环之后我会有不同的引脚具有不同的值(位置和名称)