Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello..i have two drawn circle on the map and i want when i click on the circle display the circle name..plz help me

JavaScript
function init() {  //this function will display the map
    var mapDiv = document.getElementById('map-canvas');
    var map = new google.maps.Map(mapDiv, {
        center: new google.maps.LatLng(37.790234970864, -122.39031314844),
        zoom: 8,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });


    var mapcity = {};
    mapcity['amman'] = { name: 'circle1', center: new google.maps.LatLng(37.790234970864, -122.39031314844), population: 50000 };
    mapcity['zarqa'] = { name: 'circle2', center: new google.maps.LatLng(38.790234970864, -122.39031314844), population: 100000 };
    var x = 0; //this value for inrement of the array
    var obj = new Array();
    for (var city in mapcity) {

        if (mapcity[city].population > 60000) {
            var color = 'ffffff'
        }
        else {
            var color = 'aa34ff'
        }

        var cityInfo = {
            strokeWeight: 2,
            fillColor: color,
            center: mapcity[city].center,
            radius: mapcity[city].population,
            map: map,
            strokeColor: 'red',
            strokeOpacity: 0.8,
            fillOpacity: 0.3,
            name: mapcity[city].name,

        };
        obj[x] = new google.maps.Circle(cityInfo);

        x++;
}

    google.maps.event.addListener(obj[x], 'click', function () {

        alert(obj[x].name);
    });

}
google.maps.event.addDomListener(window, 'load', init);// this function will call the init function when page load
Posted
Comments
Sunasara Imdadhusen 10-Sep-13 8:54am    
have u tried on google?
amr mustafa 10-Sep-13 8:55am    
tried what?

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