我用自定义PNG标记创建了一个简单的地图。是否可以抵消附加的PNG图像? Google Map API v3文档中似乎没有提及“偏移”。
最佳答案
从v3.10开始,已弃用MarkerImage
类,而应改用Icon
匿名对象。来自the documentation
在Google Maps JavaScript API版本3.10之前,复杂的图标被定义为MarkerImage对象。 Icon对象文字是在3.10版中添加的,并且从3.11版开始替换了MarkerImage。
例如:
var marker = new google.maps.Marker({
map:map,
position: map.getCenter(),
icon: {
url: place.icon,
size: new google.maps.Size(71, 71),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(17, 34),
scaledSize: new google.maps.Size(25, 25)
}
});
example fiddle
代码段”
function initialize() {
var mapCanvas = document.getElementById('map');
var mapOptions = {
center: new google.maps.LatLng(44.5403, -78.5463),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(mapCanvas, mapOptions)
var marker = new google.maps.Marker({
map: map,
position: map.getCenter(),
icon: {
url: "http://i.stack.imgur.com/PYAIJ.png",
size: new google.maps.Size(36, 36),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(18, 18),
scaledSize: new google.maps.Size(25, 25)
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
html,
body,
#map {
width: 100%;
height: 100%;
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map"></div>