Well,I am trying to find the latitude and longitude of a given address.The address comes from a textarea and then when i click a button,it gives me the latitude and longitude of the entered address as an alert.I am using the below script:
<script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3&sensor=false&key=AIzaSyDVk87DSFyZlxmYAM8NPNr8sZPN60FYLNA"></script>
<script type="text/javascript">
function calculateCoordinates() {
var lblStreetAddress = document.getElementById('<%= lblStreetAddress.ClientID%>');
var lblLandmark = document.getElementById('<%= lblLandmark.ClientID%>');
var lblCity = document.getElementById('<%= lblCity.ClientID%>');
var lblState = document.getElementById('<%= lblState.ClientID%>');
var lblZipCode = document.getElementById('<%= lblZipCode.ClientID%>');
var txtLatitude = document.getElementById('<%= txtLatitude.ClientID%>');
var txtLongitude = document.getElementById('<%= txtLongitude.ClientID%>');
var address = lblStreetAddress.value + ', ';
address += lblLandmark.value + ', ';
address += lblCity.value + ', ';
address += lblZipCode.value + ', ';
address += lblState.value;
var geocoder;
geocoder = new google.maps.Geocoder();
geocoder.geocode({ address: address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var location = results[0].geometry.location;
txtLatitude.value = location.lat();
txtLongitude.value = location.lng();
}
else
alert(searchString + ' - not found');
});
}
</script>
<asp:TextBox id="txtLatitude" runat="server" Width="100px"></asp:TextBox>
<asp:TextBox id="txtLongitude" runat="server" Width="100px"></asp:TextBox>
This works absolutely fine but what i really want is 1.I want to use a Label instead of a textarea because the address should come from database. 2.I want to pass the latitude and longitude value to couple of labels so that i can store them back in the database.
Is it possible? If not,are there any alternative ways which arent so complex?