2012-11-12 44 views
3

如何使用最新版本的GMaps.js更改我在代碼中設置的圖釘圖標?如何更改Gmaps.js在Google地圖中使用的圖標?

這裏就是我想要做的事:

$('input[name="Address"]').blur(function() { 
    GMaps.geocode({ 
     address: $('input[name="Address"]').val(), 
     callback: function (results, status) { 
      if (status == 'OK') { 
       var latlng = results[0].geometry.location; 
       map.setCenter(latlng.lat(), latlng.lng()); 
       map.addMarker({ 
        lat: latlng.lat(), 
        lng: latlng.lng(), 
        icon: { 
         image: "http://i.imgur.com/12312.png" 
        } 
       }); 
      } 
     } 
    }); 
}); 

運行此腳本,下面的錯誤爆發在Firebug的控制檯:

"NetworkError: 404 Not Found - http://localhost:17680/Account/undefined" 

"NetworkError: 404 Not Found - http://localhost:17680/Account/undefined" 

我不明白爲什麼它試圖因爲我從來沒有在代碼中的任何地方調用它,所以HTTP GET那個URL。

+0

@RASG:我已經回答了我的問題,謝謝! – sergserg

回答

5

更改標記上的圖標非常簡單。

如果你讀了documentation,注意到它說:

此外,createMarker接受google.maps.MarkerOptions 定義的任何選項,並在google.maps.Marker定義的任何標記的事件(「活動」部分)。

如果你讀了谷歌documentation,它只是一個調用的事:

icon: "some-url-here" 

在我的情況是:

$('input[name="Address"]').blur(function() { 
    GMaps.geocode({ 
     address: $('input[name="Address"]').val(), 
     callback: function (results, status) { 
      if (status == 'OK') { 
       var latlng = results[0].geometry.location; 
       map.setCenter(latlng.lat(), latlng.lng()); 
       map.addMarker({ 
        lat: latlng.lat(), 
        lng: latlng.lng(), 
        icon: "/images/mapicon.png" 
       }); 

       $('input[name="Longitude"]').val(latlng.lng()); 
       $('input[name="Latitude"]').val(latlng.lat()); 
      } 
     } 
    }); 
}); 
相關問題