我想使用谷歌地图,但只在国家一级,即我想在单个窗口中显示整个世界地图,用户应该能够在点击国家时选择任何国家,我也应该能够显示一些弹出窗口。我也想要从 JS 中获取国家/地区的值。请指导我。我对此进行了谷歌搜索,但没有完整的信息。
问问题
1356 次
1 回答
0
结合这两个例子:
var map=null;
var geocoder = null;
var kmlLayer = null;
var infoWindow = new google.maps.InfoWindow(); // InfoWindow
function openIW(layerEvt) {
if (layerEvt.row) {
var content = layerEvt.row['admin'].value;
} else if (layerEvt.featureData) {
var content = layerEvt.featureData.name;
}
document.getElementById('info').innerHTML = "you clicked on:<br>"+content;
findAddress(content);
}
function initialize() {
geocoder = new google.maps.Geocoder();
var chicago = new google.maps.LatLng(36.4278,-15.9);
var myOptions = {
zoom: 2,
center: chicago,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
google.maps.event.addListener(map, "click", function() {
document.getElementById('info').innerHTML = "";
});
kmlLayer = new google.maps.KmlLayer('http://www.geocodezip.com/geoxml3_test/world_countries_kml.xml', {preserveViewport: true, suppressInfoWindows: true} );
kmlLayer.setMap(map);
google.maps.event.addListener(kmlLayer, 'click', openIW);
}
function findAddress(address) {
if ((address != '') && geocoder) {
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results && results[0] && results[0].geometry && results[0].geometry.viewport)
map.fitBounds(results[0].geometry.viewport);
} else {
alert("No results found");
}
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
}
于 2013-06-26T13:56:27.320 回答