I have been struggling with this for hours, my problem is:
I have created a google map in my asp page, and I want to display the lat and lng in the Textbox by clicking on the map.
Here is the code.
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>