I have a textbox in my page which gets a location name and button with text getLat&Long
. Now on clicking my button i have to show an alert of latitiude
and longitude
of the location in the textbox. Any suugestion.
views:
61answers:
1
+2
A:
You can use the Google Geocoder service in the Google Maps API to convert from your location name to a latitude and longitude. So you need some code like:
var geocoder = new google.maps.Geocoder();
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK)
{
// do something with the geocoded result
//
// results[0].geometry.location.latitude
// results[0].geometry.location.longitude
}
});
Update
Are you including the v3 javascript API?
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=set_to_true_or_false">
</script>
Cannonade
2010-08-16 06:11:05
@Cannonade Error-`google.maps.Geocoder();` is not a constructor.
Chandra
2010-08-16 07:00:21