0
我試圖添加自定義圖像作爲谷歌地圖圖標。目前我的自定義圖像沒有顯示,但地圖可以正常工作。我想在這裏效仿:http://google-maps-utility-library-v3.googlecode.com/svn-history/r150/trunk/markerwithlabel/docs/examples.html使用MarkerWithLabel添加自定義標記圖像
代碼:
<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>
有一個在您的文章沒有代碼來創建自定義標記圖標。 – geocodezip 2014-11-03 02:36:12