ここに私のコードの一部があります:
<asp:HiddenField id="hdnLocationLatLng" runat="server" Value="0" />
そして、これを使用して、 hdnLocationLatLng の値をマーカーの現在の位置の latlng の値に設定しようとしています:
google.maps.event.addListener(map, 'click', function (event) {
if (marker) {
marker.setMap(null);
}
marker = new google.maps.Marker({
position: event.latLng,
map: map,
draggable: true,
title: "My Event's Location",
});
document.getElementById("#<%= hdnLocationLatLng.ClientID %>").value = marker.getPosition();
});
しかし、マップをクリックするたびにエラーが発生しました:
Uncaught Type Error: Cannot set property 'value' of null.
参考までに、marker.getPosition() の値を問題なく取得できます (アラートで表示しようとすると、正しい値が返されます)。