【发布时间】:2017-03-02 20:15:02
【问题描述】:
我设法为图像标记设置了一个自定义图标(图标的 URL 在代码中),但我不知道如何自定义它的大小。我在网上四处寻找帮助,但由于我的编码知识非常有限,无法添加使其工作所需的代码。有人可以将完整的完成代码发送给我,其中包含自定义市场图标宽度/高度所需的修改吗?
谢谢!
<script src='https://maps.googleapis.com/maps/api/js?v=3.exp&key=AIzaSyDL51DzuRotMkfR09g540u2dZHlKPMpR54'></script>
<div style='overflow:hidden;height:450px;width:100%;'>
<div id='gmap_canvas' style='height:450px;width:100%;'></div>
<style>
#gmap_canvas img {
max-width:none!important;
background:none!important
}
</style>
</div>
<script type='text/javascript'>
function init_map(){
var myOptions = {
scrollwheel: false,
draggable: false,
zoom:16,
center:new google.maps.LatLng(25.841211,-80.308539),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('gmap_canvas'), myOptions);
marker = new google.maps.Marker({
map: map,
position: new google.maps.LatLng(25.841211,-80.308539),
icon: 'http://www.ssglobalsupply.com/images/location-contact.png'
});
infowindow = new google.maps.InfoWindow({
content:'6891 NW 74th St Medley, FL 33166<br>'
});
google.maps.event.addListener(marker, 'click', function(){
infowindow.open(map,marker);
});
infowindow.open(map,marker);
}
google.maps.event.addDomListener(window, 'load', init_map);
google.maps.event.addDomListener(window, "resize", function() {
var center = map.getCenter();
google.maps.event.trigger(map, "resize");
map.setCenter(center);
});
</script>
【问题讨论】:
-
您希望它是什么尺寸?你看过icon sizing 上的文档吗?另外,请参阅此示例:developers.google.com/maps/documentation/javascript/examples/…
-
我看了很多东西,但我执行的代码是错误的。如果可以发送完整的完成代码并添加尺寸调整。我希望它是 50 像素 x 50 像素
-
发布您所拥有的不起作用的内容,最好是minimal reproducible example。
-
我在图标图片的 url 后面添加了“new google.maps.Size(42,68)”。
-
所以,图标:'ssglobalsupply.com/images/location-contact.png',newgoogle.maps.Size(42,68)});