我有一个谷歌地图应用程序,我想放置自定义图标而不是通常显示的通用红色图标。但无论我做什么,我都无法设置不同的图标,它总是显示为红色。我读到您不能在图标的 url 中包含 https,所以我将其上传到图像主机,但我仍然无法更改图标。如何在地图上获得自定义图标,还是必须使用 bing?
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
zoom: 10,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
}
function codeAddress() {
initialize();
var address = document.getElementById("address").value;
range = document.getElementById("distance").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
icon: "http://labs.google.com/ridefinder/images/mm_20_red.png"
position: results[0].geometry.location
});
lat1 = results[0].geometry.location.lat();
lng1 = results[0].geometry.location.lng();
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
load();
}
注意它在哪里说:
icon: "http://labs.google.com/ridefinder/images/mm_20_red.png"
不管我改变了什么,它总是显示红色的通用图标。