Friends,
Now i am using google API for getting the Location Info.I am getting the location info but i am not able to store that neither in variable nor in a hidden field. Can any one help me to know where i am doing mistake.
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script language="javascript" type="text/javascript">
var map;
var geocoder;// = new google.maps.Geocoder();
var address;
function initialize() {
var latlng = new google.maps.LatLng(document.getElementById("<%=txtLatitude.ClientID %>").value, document.getElementById("<%=txtLongitude.ClientID %>").value);
var myOptions = {
zoom: 5,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map"), myOptions);
var marker = new google.maps.Marker(
{
position: new google.maps.LatLng(document.getElementById("<%=txtLatitude.ClientID %>").value, document.getElementById("<%=txtLongitude.ClientID %>").value),
map: map,
title: 'Click me'
});
geocoder = new google.maps.Geocoder();
geocoder.geocode({ "latLng": latlng }, function(data, status) {
if (status == google.maps.GeocoderStatus.OK) {
address = data[0].formatted_address;
alert(address);
}
});
var infowindow = new google.maps.InfoWindow({
content: 'Location info:' + address + '<br/>LatLng:' + document.getElementById("<%=txtLatitude.ClientID %>").value + ',' + document.getElementById("<%=txtLongitude.ClientID %>").value
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});
}
window.onload = initialize;
</script>
You have an error. You are initializing the infowindow with the content before assigning to the marker. Set the content in the event handler.
This is how your code should be-