簡體   English   中英

Google會放置API圖標

[英]Google places API icons

我正在使用Google的Places API(http://code.google.com/apis/maps/documentation/places/)。 我想使用Google傳遞的圖標作為地方結果集的一部分,但它們看起來很大且超出規模。

根據Google關於Marker對象的文檔,Marker.setIcon方法應自動縮放圖像以適合地圖。

我正在使用這樣的東西:

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

它工作,但圖像不縮放。 無論如何,它似乎約為75px平方。 我也嘗試將這個圖像寫入一個新的MarkerImage對象,然后我可以進行縮放,但這似乎相當復雜。

有沒有讓圖標圖像正確縮放的技巧?

好的,我沒有在這里得到任何想法,所以我繼續創建一個新的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
  });
}
                    }

更新的方法是:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM