Javascript 谷歌地图API自定义图标与SSL
我有一个谷歌地图应用程序,我想把自定义图标,而不是一般的红色图标,通常会出现。但无论我做什么,我不能设置一个不同的图标,它总是显示为红色的。我读到你不能在图标的url中使用https,所以我将其上传到了一个图像主机,但我仍然无法更改图标。如何在地图上获得自定义图标,还是必须使用bingJavascript 谷歌地图API自定义图标与SSL,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我有一个谷歌地图应用程序,我想把自定义图标,而不是一般的红色图标,通常会出现。但无论我做什么,我不能设置一个不同的图标,它总是显示为红色的。我读到你不能在图标的url中使用https,所以我将其上传到了一个图像主机,但我仍然无法更改图标。如何在地图上获得自定义图标,还是必须使用bing function initialize() { geocoder = new google.maps.Geocoder(); var latlng = new google.maps.LatLng
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"
无论我做了什么更改,它都会显示红色的通用图标。您可以通过页面上的
HTTP
和HTTPS
加载标记图像。但是,您需要确保方案与包含页面的方案匹配(或者,如果页面也匹配,至少要确保使用HTTPS
)
您的标记选项
对象似乎有输入错误:图标字符串后缺少逗号
var marker = new google.maps.Marker({
map: map,
icon: "http://labs.google.com/ridefinder/images/mm_20_red.png",
position: results[0].geometry.location
});
请参阅关于{custommarkers]()的文档,向我们展示您的代码是什么样子的(应该可以工作)。