谷歌地图API图标

4
我正在使用Google的Places API(http://code.google.com/apis/maps/documentation/places/)进行工作。我想使用Google作为places结果集的一部分传递的图标,但它们看起来非常巨大并且不成比例。
根据Google关于标记对象的文档,Marker.setIcon方法应该自动缩放图像以适合地图大小。
我正在使用类似以下的代码:
var marker      = new google.maps.Marker({
                                      map: map,
                                      position: place.geometry.location
                 });
marker.setIcon(place.icon);

代码能够正常运作,但是图像没有按比例缩放。无论什么情况下,它似乎都是大约75像素的正方形。我也尝试将此图像写入新的MarkerImage对象中,然后再进行缩放,但这似乎非常复杂。

有没有什么诀窍可以使图标图像正确缩放?

2个回答

7

好的,我在这里没有得到任何想法,所以我创建了一个新的MarkerImage对象并进行了缩放。效果很好,不是很优雅,但它在这里:

// pass in the place object returned by the Google Place API query
function createPlace(place){
  var gpmarker    = new google.maps.MarkerImage(place.icon, null, null, null, new google.maps.Size(25, 25));
  var marker      = new google.maps.Marker({
    map: map,
    position: place.geometry.location,
    title: place.name,
    icon: gpmarker
  });
}
                    }

正是我所寻找的,即缩小默认图标的大小。我本来会花很多时间自己解决这个问题,但这个答案完全帮助了我。我只需要复制粘贴它 :) - whizcreed

5
更新的做法是:
var image = {
  url: place.icon,
  size: new google.maps.Size(71, 71),
  origin: new google.maps.Point(0, 0),
  anchor: new google.maps.Point(17, 34),
  scaledSize: new google.maps.Size(25, 25)
};

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接