tags:

views:

50

answers:

1

Does anyone know how make the default Google map interface display long and lat coordinates in an info window when the user clicks on the map?

Header code:

<script src="http://maps.google.com/maps?file=api&amp;amp;v=2&amp;amp;sensor=true&amp;amp;key=ABQIAAAAZ6eT28fkj8_qRULTI6L0HBRQxZU5pk4gyaqNiN8f5B0Lcg03_BRT9YfVR6upxmqNPUmV3LWLAq5WDg" type="text/javascript"></script>
<script type="text/javascript">
function initialize() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map"));
    map.setCenter(new GLatLng(13.175771, -59.556885), 10);
    map.setUIToDefault();
  }
}
</script>

Body code:

<div id="map" style="width: 640px; height: 300px"></div>
+4  A: 
 google.maps.event.addListener(map, 'click', function(event) {
    new google.maps.InfoWindow({
      position: event.latLng,
      content: event.latLng.toString() 
    }).open(map);
 });
Sudhir Jonathan
Jonathan, thanks, but not sure where to use that. Should I add that function to the header Javascript?
trnsfrmr
I've edited my original question to include my header and body code.
trnsfrmr
Do you really need use the deprecated version 2 of the api? I've given you code for v3, which is the current version.
Sudhir Jonathan
Awesome! It works! Thanks!
trnsfrmr
If you're interested, you have helped me add a neat little map coordinate getter to the end of this form: http://www.barbadosphonebook.com/list-your-business-for-free/
trnsfrmr
Nice :D Why not just put the numbers in directly? Saves the user a step...
Sudhir Jonathan
I couldn't work out to do the auto number input.
trnsfrmr
Ask another question about that :D. And put the link in these comments, I'll come and answer it.
Sudhir Jonathan
Thanks. Will do that soon; once I scoop-up the details for the question.
trnsfrmr
Hey Sudhir Jonathan, here's the question for you: http://stackoverflow.com/questions/3953659/how-do-i-use-google-map-data-in-other-form-elements
trnsfrmr