我的代码如下。它现在正在工作,但如果我取消注释图标行(// icon:'http://108.163.162.202:8080/finex/img/map_marker.png'),则不会显示所有标记及其标题。
我想在我的页面中添加自定义标记,而我的代码不允许我。
请提前帮助谢谢
$(function() {
var locations = [
['Jersey City', 40.7178746, -74.0718356],
['Bronx', 40.8504989, -73.84934,5 ],
['Union City', 40.7667435, -74.0303289],
['Queens', 40.651018, -73.871192],
['Ridgefield', 40.8256436, -74.0153092]
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 11,
center: new google.maps.LatLng(40.7590615, -73.969231),
mapTypeId: google.maps.MapTypeId.ROADMAP,
scrollwheel: false,
mapTypeControl: false,
scaleControl: false,
navigationControl: true,
draggable: false,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.LARGE
},
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map,
title: locations[i][0],
//icon: 'http://108.163.162.202:8080/finex/img/map_marker.png',
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(marker.title);
infowindow.open(map, marker);
}
})(marker, i));
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<div style="height:300px;width:500px;" id="map"></div>
答案 0 :(得分:2)
I did this in my project
<input type="hidden" value="http://108.163.162.202:8080" id="baseUrl" >
var baseUrl=$('#baseUrl').val();
icon: new google.maps.MarkerImage(
baseUrl+'images/marker-new.png',
null,
null,
// new google.maps.Point(0,0),
null,
new google.maps.Size(36, 36)
),
答案 1 :(得分:1)
使用.htaccess进行图像访问受限。我必须输入用户名和密码。也许这就是问题? ;) 此外,如果没有任何内容,您可以在icon语句后面留下逗号。