【发布时间】:2014-11-03 00:36:14
【问题描述】:
我正在尝试将自定义图像添加为谷歌地图图标。目前我的自定义图像没有显示,但地图可以正常工作。我正在尝试按照此处的示例进行操作:http://google-maps-utility-library-v3.googlecode.com/svn-history/r150/trunk/markerwithlabel/docs/examples.html
代码:
<script src="https://maps.googleapis.com/maps/api/js"></script>
<script type="text/javascript" src="js/markerwithlabel.js"></script>
<script>
function initialize() {
var myLatlng = new google.maps.LatLng(42.350358,-71.0851531);
var mapOptions = {
zoom: 13,
center: myLatlng
}
var map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
var pictureLabel1 = document.createElement("img");
pictureLabel1.src = "images/cake.png";
var pictureLabel2 = document.createElement("img");
pictureLabel2.src = "images/hotel.png";
var marker1 = new MarkerWithLabel({
position: new google.maps.LatLng(42.341239,-71.111074),
map: map,
labelContent: pictureLabel1,
labelAnchor: new google.maps.Point(50,30),
labelClass: "labels",
labelInForeground: true
});
var marker2 = new MarkerWithLabel({
position: new google.maps.LatLng(42.3416983,-71.0705033),
map: map,
labelContent: pictureLabel2,
labelAnchor: new google.maps.Point(1,30),
labelClass: "labels",
labelInForeground: true
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
【问题讨论】:
-
您的帖子中没有创建自定义标记图标的代码。
标签: javascript html google-maps google-maps-api-3