您如何使用Google Maps API v3的自定义图标创建标记? [英] How do you create a Marker with a custom icon for google maps API v3?
本文介绍了您如何使用Google Maps API v3的自定义图标创建标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在阅读 https://developers.google.com/maps/documentation / javascript / overlays 一段时间后,我似乎无法获得我的地图工作的自定义图标。
这是我的javascript:
var simplerweb = new google.maps.LatLng(55.977046,-3.197118);
var marker;
var map;
函数initialize(){
var myOpts = {
center:simplerweb,
zoom:15,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById(map_canvas),myOpts);
marker = new google.maps.Marker({
map:map,
draggable:true,
animation:google.maps.Animation.DROP,
position: simplerweb
});
google.maps.event.addListener(标记,'click',toggleBounce);
函数toggleBounce(){
if(marker.getAnimation()!= null){
marker.setAnimation(null);
} else {
marker.setAnimation(google.maps.Animation.BOUNCE);
$ b $ p $ g
$ b $ p>
解决方案
- demo: http: //so.lucafilosofi.com/how-do-you-create-a-marker-with-a-custom-icon-for-google-maps-api-v3
marker = new google.maps.Marker({
map:map,
// draggable:true,
//动画:google.maps.Animation.DROP,
位置:新google.maps.LatLng(59.32522,18.07002),
图标:' http://cdn.com/my-custom-icon.png'// null =默认图标
});
I've been reading https://developers.google.com/maps/documentation/javascript/overlays for a while now and I can't seem to get a custom icon for my map working.
Here is my javascript:
var simplerweb = new google.maps.LatLng(55.977046,-3.197118);
var marker;
var map;
function initialize() {
var myOpts = {
center: simplerweb,
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOpts);
marker = new google.maps.Marker({
map: map,
draggable: true,
animation: google.maps.Animation.DROP,
position: simplerweb
});
google.maps.event.addListener(marker, 'click', toggleBounce);
}
function toggleBounce() {
if (marker.getAnimation() != null) {
marker.setAnimation(null);
} else {
marker.setAnimation(google.maps.Animation.BOUNCE);
}
}
Any pointers for a complete beginner with gmaps?
解决方案
marker = new google.maps.Marker({
map:map,
// draggable:true,
// animation: google.maps.Animation.DROP,
position: new google.maps.LatLng(59.32522, 18.07002),
icon: 'http://cdn.com/my-custom-icon.png' // null = default icon
});
这篇关于您如何使用Google Maps API v3的自定义图标创建标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文