Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding click listener on circle is not working

I am trying to add click listener on my map and here is my code for this

update

<!DOCTYPE html>
<html>
  <head>
  <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
</head>
<style>
    #map-canvas{
 width:500px; 
 height:500px;
}
</style>
<script  type="text/javascript">
    var cityPoints = {
        center: new google.maps.LatLng(41.878113, -87.629798),
        id: 0,
        addr: 'avenue0',
        magnitude: 100000
    };

    var cityCircle;
    var infoWindow = new google.maps.InfoWindow({
        content: "<div>Hello! World</div>",
        maxWidth: 500
    });


  function initialize() {
 var mapOptions = {
     zoom: 4,
     center: new google.maps.LatLng(31.2330555556, 72.3330555556),
     mapTypeId: google.maps.MapTypeId.TERRAIN
 };

  var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

  var populationOptions = {
      strokeColor: "#FF0000",
      strokeOpacity: 1,
      strokeWeight: 1,
      clickable: true,
      fillOpacity: 0,
      map: map,
      center: new google.maps.LatLng(31.231867, 72.33336),
      radius: 200000
  };

  cityCircle = new google.maps.Circle(populationOptions);


    google.maps.event.addListener(cityCircle, 'click', function (ev) {
        infoWindow.setPosition(ev.latLng);
        infoWindow.open(map);
    });
}
initialize();
</script>
<body>
    <div id="map-canvas"></div>
</body>
</html>

But this code is not working for me becasue infor window is not opening when i click on circle.Plz any one tell what exactly i am missing in my code.Plz Help

like image 419
user2024024 Avatar asked May 23 '13 07:05

user2024024


1 Answers

Maybe this google.maps.event.addDomListener(window, 'load', initialize); is what is missing. And here is a working example

http://jsfiddle.net/9bnCw/6/

I made the radius a little bigger.

UPDATE

Does this work?

UPDATE 3

I've put it all in one file so you can copy and paste it.

<!DOCTYPE html>
<html> 
    <head>
        <style>
 #map-canvas{ 
 height:100%;
 width:100%;           
}
 html, body {
     height: 100%;
 }    
 body {
     margin:0;
     padding:0;
 }           
        </style>
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
        <script>
            var cityPoints = {
  center: new google.maps.LatLng(41.878113, -87.629798),
  id: 0,
  addr: 'avenue0',
  magnitude: 100000
};

var cityCircle;
var infoWindow = new google.maps.InfoWindow({
        content: "<div>Hello! World</div>",
        maxWidth: 500
    });

function initialize() {
  var mapOptions = {
    zoom: 4,
    center: new google.maps.LatLng(31.231867, 72.33336),
    mapTypeId: google.maps.MapTypeId.TERRAIN
  };

  var map = new google.maps.Map(document.getElementById('map-canvas'),
      mapOptions);

           var populationOptions = {
        strokeColor: "#FF0000",
        strokeOpacity: 1,
        strokeWeight: 1,
        clickable: true,
        fillOpacity: 0,
        map: map,
        center: new google.maps.LatLng(31.231867, 72.33336),
        radius: 200000
    };
    cityCircle = new google.maps.Circle(populationOptions);

    google.maps.event.addListener(cityCircle, 'click', function(ev) {
            infoWindow.setPosition(ev.latLng);
            infoWindow.open(map);
        });
}
google.maps.event.addDomListener(window, 'load', initialize);

        </script>  
    </head>
<body>
    <div id="map-canvas"></div>
</body>
</html>
like image 199
Alkis Kalogeris Avatar answered Nov 15 '22 23:11

Alkis Kalogeris