Google maps api 3 更改多个自定义标记图标的点位置Google Map API V3

Google maps api 3 更改多个自定义标记图标的点位置Google Map API V3,google-maps-api-3,icons,markers,Google Maps Api 3,Icons,Markers,我需要能够更改标记图标的点位置,其中每个标记位置都有一个单独的图标。图标需要在锚点上居中,而不是在底部居中,因为它们是默认的 如果不完全重新编写我的代码,我就想不出如何做到这一点 var sites = [ ['Photo 1', 36.33835943134047, -93.63535, 4, 'mylinkurl', 'images/marker1.png'], ['Photo 2', 36.315939, -94.440630, 2, 'mylinkurl', 'images/marker

我需要能够更改标记图标的点位置,其中每个标记位置都有一个单独的图标。图标需要在锚点上居中,而不是在底部居中,因为它们是默认的

如果不完全重新编写我的代码,我就想不出如何做到这一点

var sites = [
['Photo 1', 36.33835943134047, -93.63535, 4, 'mylinkurl', 'images/marker1.png'],
['Photo 2', 36.315939, -94.440630, 2, 'mylinkurl', 'images/marker2.png'],
['Photo 3', 36.085890, -93.90175, 1, 'mylinkurl', 'images/marker3.png'],
   ['Photo 4', 36.09948, -93.28370, 3, 'mylinkurl', 'images/marker4.pngg']
];


function setMarkers(map, markers) {

    for (var i = 0; i < markers.length; i++) {
        var sites = markers[i];
        var siteLatLng = new google.maps.LatLng(sites[1], sites[2]);
        var marker = new google.maps.Marker({
            position: siteLatLng,
            map: map,
            icon: sites[5],
            title: sites[0],
            zIndex: sites[3],
            href: sites[4]
        });


    google.maps.event.addListener(marker, 'click', function() {     
        $.fancybox({
            href : this.href,
            width : 1000,
            maxHeight   : 666,
            fitToView   : true,
            autoSize    : false,
            type: 'iframe',
            padding: 0,
            openEffect : 'elastic',
            openSpeed  : 150,
            aspectRatio : true,
            closeEffect : 'elastic',
            closeSpeed  : 150,
            closeClick : true,
            iframe : { scrolling : 'no'
            },
            preload   : false
        });
    });
     arrMarkers.push(marker);
    }

}

谢谢你。我想我的挣扎是我不知道如何将它整合到我的代码中。。。我需要那个图标url来自字符串。。。尝试这个,但不起作用:

    function setMarkers(map, markers) {

    for (var i = 0; i < markers.length; i++) {
        var sites = markers[i];
        var sites = markers[i];
        var siteLatLng = new google.maps.LatLng(sites[1], sites[2]);                    
  var icon = { 
         url: sites[5],
         size: new google.maps.Size(40,40),
         anchor: new google.maps.Point(20,20)
       };
      var marker = new google.maps.Marker({
            position: siteLatLng,
            map: map,
            icon: sites[5],
            title: sites[0],
            zIndex: sites[3],
            href: sites[4]
        });
函数设置标记(映射,标记){
对于(var i=0;ivar marker=new google.maps.marker({
职位:siteLatLng,
地图:地图,
图标:站点[5],
标题:站点[0],
zIndex:sites[3],
href:sites[4]
});

如果您使用的是本机Google Maps API v3图标,我会说以下内容。这就是您的问题所在

但是,在您提供链接(1)的地图上,您正在使用KMZ文件作为开放式标志(2),这些是您关心的图标吗?要将这些图标居中,您需要添加

你需要:

var icon = { 
             url: 'your/URL/for the icon",
             size: new google.maps.Size(40,40),
             anchor: new google.maps.Point(20,20)
           };

var marker=new google.maps.marker({position:siteLatLng,map:map,icon:icon,title:sites[0],zIndex:sites[3],href:sites[4]});
(1)     http://url/

(2)     http://url/OpenHouse.kmz

<hotSpot x="0.5" y="0.5" xunits="fraction" yunits="fraction">
google.maps.Icon object specification
Properties | Type   | Description
anchor     | Point  | The position at which to anchor an image in correspondance to the     location of the marker on the map. By default, the anchor is located along the center point of the bottom of the image.
origin     | Point  | The position of the image within a sprite, if any. By default, the origin is located at the top left corner of the image (0, 0).
scaledSize | Size   | The size of the entire image after scaling, if any. Use this property to stretch/shrink an image or a sprite.
size       | Size   | The display size of the sprite or image. When using sprites, you must specify the sprite size. If the size is not provided, it will be set when the image loads.
url        | string | The URL of the image or sprite sheet.
var icon = { 
             url: 'your/URL/for the icon",
             size: new google.maps.Size(40,40),
             anchor: new google.maps.Point(20,20)
           };