如何在谷歌地图api V3中居中图像锚?

时间:2011-06-18 16:11:38

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

我正试图在google maps api here中将图标的锚点居中,但是当我尝试爆炸图像时,它会消失。

此代码工作正常但锚点位于图像的底部中心:

  var image_explode = 'images/map/explode.png';
  var explode_longlat = new google.maps.LatLng(-18.142599, 178.431);
  var explode = new google.maps.Marker({
      position: explode_longlat,
      map: map,
      icon: image_explode
  });

我尝试使用此代码使锚点居中,但它消失了:

  var image_explode = new google.maps.MarkerImage("projectstratos.com/images/map/explode.png",new google.maps.Size(20,20),new google.maps.Point(0,0),new google.maps.Point(10,10));
  var explode_longlat = new google.maps.LatLng(-18.142599, 178.431);
  var explode = new google.maps.Marker({
      position: explode_longlat,
      map: map,
      icon: image_explode
  });

1 个答案:

答案 0 :(得分:2)

如果要包含主机名,则需要URL中的方案(http://):

  var explode_image = new google.maps.MarkerImage("http://projectstratos.com/images/map/explode.png", new google.maps.Size(20,20), new google.maps.Point(0,0), new google.maps.Point(10,10));
  var explode_longlat = new google.maps.LatLng(-18.142599, 178.431);
  var explode = new google.maps.Marker({
      position: explode_longlat,
      map: map,
      icon: explode_image
  });

或者,请关闭主机名(projectstratos.com)。