2013-06-26 143 views
0

我想使用谷歌地圖,但只在國家一級,即我想在單個窗口中顯示整個世界地圖,用戶應該能夠選擇任何國家點擊國家,我也應該能夠顯示一些彈出窗口。我也想獲得從JS選擇的國家的價值。請在此引導我。我做過谷歌,但沒有完整的信息。允許選擇國家和放大到國家級別

+0

[變焦到國家](http://geocodezip.com/v3_zoom2countrySelectList.html ) - [可點擊的世界地圖](http://www.geocodezip.com/v3_GoogleEx_layer-kml _world_countries_simple.html) – geocodezip

+0

感謝用Zooom輸入問題給國家的例子是我們需要從下拉菜單中選擇國家用戶放置鼠標並選擇和higher – Ashwin

+0

不能真正「選擇和突出顯示」。您可以合併這兩個示例,單擊一個國家並縮放地理編碼器返回的邊界。 – geocodezip

回答

0

結合這兩個例子:

  1. Zoom to country
  2. clickable world map

click to zoom to country

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); 
     } 
    }); 
    } 
} 
+0

是否有多種選擇的選項 – Ashwin

+0

當然有。您只需定義功能並對其進行編碼即可。 – geocodezip

+0

謝謝!我怎樣才能創建一個谷歌地圖的圖像 – Ashwin