我已经为此苦苦挣扎了几个小时,我的问题是:
我在我的asp页面中创建了一个谷歌地图,我想通过点击地图在文本框中显示纬度和经度。
这是代码。
Javascript:
var map;
var marker = null;
var latitudeTextBox = $("#<%= LatitudeTextBox.ClientID %>");
var longitudeTextBox = $("#<%= LongitudeTextBox.ClientID %>");
function initialize() {
var myCenter = new google.maps.LatLng(-33, 150.75);
var mapOption =
{
center: myCenter,
zoom: 7,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("googleMap"), mapOption);
google.maps.event.addListener(map, 'click', function (event) {
createNewMarker(event.LatLng,map);
});
google.maps.event.addDomListener(window, 'load', initialize);
}
function createNewMarker(location,map) {
if (marker != null)
marker.setMap(null);
marker = new google.maps.Marker({
position: location,
animation: google.maps.Animation.BOUNCE,
map: map,
});
var infowindow = new google.maps.InfoWindow({
content: 'Latitude: ' + location.lat() + '<br>Longitude: ' + location.lng()
});
infowindow.open(map, marker);
latitudeTextBox.val(location.lat());
longitudeTextBox.val(location.lng());
}
ASP:
<asp:TextBox id="LatitudeBox" runat="server" text=""></asp:TextBox>
<asp:TextBox id="LongitudeBox" runat="server" text=""></asp:TextBox>