这是我的代码的一部分:
<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() 的值(尝试在警报中显示它并返回正确的值)。