Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google map coordinates info window on click

Tags:

google-maps

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;v=2&amp;sensor=true&amp;key=..." 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>
like image 971
jnthnclrk Avatar asked Oct 01 '10 14:10

jnthnclrk


1 Answers

 google.maps.event.addListener(map, 'click', function(event) {
    new google.maps.InfoWindow({
      position: event.latLng,
      content: event.latLng.toString() 
    }).open(map);
 });
like image 120
Sudhir Jonathan Avatar answered Sep 30 '22 02:09

Sudhir Jonathan