I want to use google map but only at the country level ie i want to show whole world map in single window and user should be able to select any country on clicking of the country , also i should be able to show some popups .I also want to get the value of country selected from JS. Please guide me on this. I did google on this but no complete info.
Combine these two examples:
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);
}
});
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.