简体   繁体   English

谷歌地图api v3图标的双重图像

[英]google maps api v3 double image for icon

 var icon = {
                    url: pointer.png,
                    size: new google.maps.Size(48,48),
                    origin: new google.maps.Point(0,0),
                    anchor: new google.maps.Point(24,24)
                  };

var marker = new google.maps.Marker({
                    position: pos,
                    map: map,
                    icon: icon
                  });

Is it possible to add second image to the marker? 是否可以向标记添加第二张图像? I'd like to have double marker for same point, 1 overlaid on top of the other. 我想对同一点使用双标记,将1标记在另一个标记之上。

I want to have little flag of country next to marker. 我想在标记旁边有一点国旗。

Possible? 可能?

Prior to the API v3.14, you hack this with a icon and a shadow image file together on the same marker. 在API v3.14之前,您可以在同一标记上同时使用iconshadow图像文件对其进行破解。

Here's how I would solve it with v3.14+ 这是我如何使用v3.14 +解决问题的方法

function initialize() {
    google.maps.visualRefresh = true;
    var mapDiv = document.getElementById('map-canvas');
    var map = new google.maps.Map(mapDiv, {
        center: new google.maps.LatLng(0, 0),
        zoom: 10,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    var marker = new google.maps.Marker({
        position: new google.maps.LatLng(0, 0),
        map: map
    });

    // CREDIT: https://developers.google.com/maps/documentation/javascript/markers
    marker.flag = new google.maps.Marker({
        icon: {
            url: 'https://google-developers.appspot.com/maps/documentation/javascript/examples/full/images/beachflag.png',
            anchor: new google.maps.Point(32, 32)
        }
    });

    marker.flag.bindTo('position', marker);
    marker.flag.bindTo('map', marker);

}

google.maps.event.addDomListener(window, 'load', initialize);

See: http://jsfiddle.net/stevejansen/J5swt/ 请参阅: http//jsfiddle.net/stevejansen/J5swt/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM