在Google Maps API V3中复制标记图标

时间:2011-03-01 08:56:24

标签: javascript google-maps google-maps-api-3

我有同样的意思来复制先前声明的标记中的图标,但它不起作用:

map = new google.maps.Map(document.getElementById('map'), {
  zoom:12,
  center:latlng2,
  mapTypeId:google.maps.MapTypeId.SATELLITE
});

marker = new google.maps.Marker({
  map:map,
  icon: new google.maps.MarkerImage(
    'http://www.gettyicons.com/free-icons/108/gis-gps/png/24/needle_left_yellow_2_24.png',
    new google.maps.Size(24, 24),
    new google.maps.Point(0, 0),
    new google.maps.Point(0, 24)
  )
});

var babyIcon = new google.maps.MarkerImage(marker.getIcon(),
  new google.maps.Size(
      marker.getIcon().size.width * this.iconScale_,
      marker.getIcon().size.height * this.iconScale_
  ),
  new google.maps.Point(0,0),
  new google.maps.Point (
      marker.getIcon().anchor.x * this.iconScale_,
      marker.getIcon().anchor.y * this.iconScale_ / 2
  )
);

// kill the shadow
babyIcon.shadow = null;

this.babyMarker_ = new google.maps.Marker({
  position:new google.maps.LatLng(0,0),
  icon: babyIcon,
  draggable:false,
  map:map
});

它不起作用,图标不显示所有这些。有什么我想念的吗?

1 个答案:

答案 0 :(得分:2)

你需要设置MarkerImage的url,你需要的属性是.ra(不要问我)

var babyIcon = new google.maps.MarkerImage(
  marker.getIcon().ra,
  new google.maps.Size(
      marker.getIcon().size.width * this.iconScale_,
      marker.getIcon().size.height * this.iconScale_
  ),
  new google.maps.Point(0,0),
  new google.maps.Point (
      marker.getIcon().anchor.x * this.iconScale_,
      marker.getIcon().anchor.y * this.iconScale_ / 2
  )
);