Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am trying to get the current location address in my infoWindow when I click on the marker that points to the current location. I think I need JavaScript to pass to the content field of the infoWindow but I cannot figure it out.

JavaScript
var infoWindow = new google.maps.InfoWindow({
  content: 'You are here'
});
								
							google.maps.event.addListener(marker, 'click', info);						
function info() {
 infoWindow.open(map, marker);
}	


Regards!
Posted

1 solution

Try this..

XML
<html>
<head>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
 <script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>
<script type="text/javascript">

  var  geocoder = new google.maps.Geocoder();
 var infowindow = new google.maps.InfoWindow();
var latlang=new google.maps.LatLng(geoip_latitude(), geoip_longitude());
  function initialize()
  {
      var myOptions = {
      center: latlang,
      zoom: 5,
      mapTypeId: google.maps.MapTypeId.ROADMAP

    };
    var map = new google.maps.Map(document.getElementById("map"), myOptions);
 geocoder.geocode({ 'latLng': latlang }, function (items, status) {

                    if (status == google.maps.GeocoderStatus.OK) {

                        map.setZoom(8);

                       var marker = new google.maps.Marker({
                            position: latlang ,
                            map: map
                        });

                     infowindow.setContent(items[1].formatted_address);
                         google.maps.event.addListener(marker, 'click', function () {


                infowindow.open(map, this);
                map.setZoom(8);
            });
                    }

                });
}


window.onload=initialize;

</script>
</head>
<body>
<div id="map" align="center" style="height: 420px;  width:500px; top:0px; border: 1px solid black;"></div>
</body>
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900