2011-04-28 39 views
3

我有我的小卡片遊戲用戶的個人資料頁,如this one - 我通過查找他們的城市來展示他們的位置。我當前的jQuery代碼是在這裏:谷歌地圖Javascript:添加用戶照片到標記

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> 
<script type="text/javascript"> 

$(function() { 
    // the city name is inserted here by the PHP script 
    findCity('New-York'); 
}); 

function createMap(center) { 
    var opts = { 
     zoom: 9, 
     center: center, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    return new google.maps.Map(document.getElementById("map"), opts); 
} 

function findCity(city) { 
    var gc = new google.maps.Geocoder(); 
    gc.geocode({ "address": city}, function(results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
      var pos = results[0].geometry.location; 
      var map = createMap(pos); 
      var marker = new google.maps.Marker({ 
       map: map, 
       title: city, 
       position: pos 
      }); 
     } 
    }); 
} 

</script> 
...... 
<div id="map"></div> 

和它工作得很好,但我只得到一個簡單的紅色標記,以點顯示:

map with a marker

有討好的方式來顯示用戶頭像而不是簡單的標記?

我有我的數據庫用戶的圖片的網址(名稱,城市等一起)

他們大多是大圖片(除200x300更大)。

回答

1

Google maps API確實支持自定義圖標,在文檔here中對此進行了說明。

可以找到一個例子here

+0

謝謝,但如何調整圖片大小,是否有必要? – 2011-04-28 13:34:36

+0

據我所知,Google地圖的圖標大小沒有限制,無法工作。不過,我會建議將它們縮小一點,因爲像這樣的大圖標肯定會以視覺方式呈現。 – Kokos 2011-04-28 13:37:07