【问题标题】:Google places API iconsGoogle 放置 API 图标
【发布时间】:2011-09-12 21:12:31
【问题描述】:

我正在使用 Google 的 Places API (http://code.google.com/apis/maps/documentation/places/)。我想使用谷歌传递的图标作为地点结果集的一部分,但它们看起来很大而且不成比例。

根据关于 Marker 对象的 Google 文档,Marker.setIcon 方法应该自动缩放图像以适应地图。

我正在使用这样的东西:

var marker      = new google.maps.Marker({
                                      map: map,
                                      position: place.geometry.location
                 });
marker.setIcon(place.icon);

它可以工作,但图像没有缩放。无论如何,它似乎约为 75px 正方形。我也尝试将此图像写入一个新的 MarkerImage 对象,然后我可以对其进行缩放,但这似乎过于复杂。

有什么技巧可以让图标图像正确缩放吗?

【问题讨论】:

    标签: javascript google-maps-api-3


    【解决方案1】:

    好的,我在这里没有任何想法,所以我继续创建了一个新的 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
      });
    }
                        }
    

    【讨论】:

    • 正是我想要的,即缩小默认图标的大小。我自己会花很多时间来解决这个问题,这个答案完全帮助了我。我只需要复制并粘贴它:)
    【解决方案2】:

    更新的方法是:

    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)
    };
    

    【讨论】:

      猜你喜欢
      • 2015-01-26
      • 1970-01-01
      • 2013-01-30
      • 2011-12-26
      • 2013-04-24
      • 1970-01-01
      • 2021-09-08
      • 1970-01-01
      • 2016-01-25
      相关资源
      最近更新 更多