[英]Only the first marker showing on google map
我在Google地图上显示地址时遇到问题。 我已经尝试了一切,但没有用。 即使我单击其他地址,它也仅显示第一个标记。 如何获得显示其他标记的信息?
<xsl:for-each select="Attractions/Museums">
<a href="#maps" data-role="button" id="addMarker" onclick="addMarker();" data-theme="c"> <xsl:value-of select="address"/></a>
</xsl:for-each>
<script type="text/javascript">
var map;
var geocoder = new google.maps.Geocoder();
$( "#maps" ).on( 'pageshow', function() {
google.maps.event.trigger(map,'resize');
})
// initialize the map
function initialize() {
var mapOptions = {
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);
function addMarker() {
var address = document.getElementById("addMarker").text;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var image = 'flag1.png';
var markers = new google.maps.Marker({
map: map,
icon: image,
position: results[0].geometry.location
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
您所有的链接(锚标记)都具有相同的ID属性,因此在函数运行时,请选择最后一个以获取标记数据。
尝试为每个链接使用不同的ID属性,并将该ID作为参数发送给函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.