2014-05-12 30 views
0

我在我的網站上繪製谷歌地圖。在我的數據庫中我有座標...我想要得到這個座標並在數據庫中繪製圓形的foreah記錄。當我畫的圓我想點擊它顯示的文字......這是我的代碼,我畫圈圈顯示味精當我點擊圓圈谷歌地圖?

<script> 
// This example creates circles on the map, representing 
// populations in the United States. 

// First, create an object containing LatLng and population for each city. 
var citymap = {}; 
citymap['chicago'] = { 
    center: new google.maps.LatLng(41.878113, -87.629798), 
    population: 2842518 
}; 
citymap['newyork'] = { 
    center: new google.maps.LatLng(40.714352, -74.005973), 
    population: 8143197 
}; 
citymap['losangeles'] = { 
    center: new google.maps.LatLng(34.052234, -118.243684), 
    population: 3844829 
}; 
var cityCircle; 

function initialize() { 
    // Create the map. 
    var mapOptions = { 
    zoom: 4, 
    center: new google.maps.LatLng(37.09024, -95.712891), 
    mapTypeId: google.maps.MapTypeId.TERRAIN 
    }; 

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

    // Construct the circle for each value in citymap. 
    // Note: We scale the population by a factor of 20. 
    for (var city in citymap) { 
    var populationOptions = { 
     strokeColor: '#FF0000', 
     strokeOpacity: 0.8, 
     strokeWeight: 2, 
     fillColor: '#FF0000', 
     fillOpacity: 0.35, 
     map: map, 
     center: citymap[city].center, 
     radius: citymap[city].population/20 
    }; 
    // Add the circle for this city to the map. 
    cityCircle = new google.maps.Circle(populationOptions); 
    } 
} 

google.maps.event.addDomListener(window, 'load', initialize); 

    </script> 

我的問題是我怎麼能證明味精當我點擊我的地圖上任何一個圓?

回答

0

你應該能夠做這樣的事情:

google.maps.event.addListener(cityCircle, 'click', function() { 
    alert('you message goes here'); 
}); 
0

Google Maps API文檔shows how to open an infowindow。一個簡單的例子,你可以在你的cityCircle定義後放:

google.maps.event.addListener(cityCircle, 'click', function() { 
    new google.maps.InfoWindow({content: 'hello!'}).open(map, cityCircle); 
}); 
+0

它不工作.... :(有沒有結果 – AsoooNol

+0

@AsoooNol:oops,我錯過了打開信息窗口的電話,現在試試嗎? –