2013-02-14 117 views
3

我遇到了一個問題,如何設置不同國家的縮放級別,我設法讓地圖工作和顯示國家,似乎無法解決如何設置縮放級別。谷歌地圖縮放級別爲國家

任何幫助,將不勝感激。

感謝

喬治

<script type="text/javascript"> 
        var infowindow = null; 
        $(document).ready(function() { initialize(); }); 

        function initialize() { 

         //var geocoder = new google.maps.Geocoder(); 
         //geocoder.geocode({ 'address': address }, function (results, status) { 
         // if (status == google.maps.GeocoderStatus.OK) { 
         //  map.setCenter(results[0].geometry.location); 
         //  map.fitBounds(results[0].geometry.viewport); 
         // } 
         //}); 

         var centerMap = new google.maps.LatLng(@Html.Raw(@item.strLatLong)); 

         var myOptions = { 
          zoom: 4, //<<-------How can I chnage this 
          center: centerMap, 
          mapTypeId: google.maps.MapTypeId.ROADMAP 
         } 

         var map = new google.maps.Map(document.getElementById("WeatherMapLocation"), myOptions); 

         setMarkers(map, sites); 
         infowindow = new google.maps.InfoWindow({ 
          content: "loading..." 
         }); 

         var bikeLayer = new google.maps.BicyclingLayer(); 
         bikeLayer.setMap(map); 
        } 



        function setMarkers(map, markers) { 

         for (var i = 0; i < markers.length; i++) { 
          var sites = markers[i]; 
          var siteLatLng = new google.maps.LatLng(sites[1], sites[2]); 
          var marker = new google.maps.Marker({ 
           position: siteLatLng, 
           map: map, 
           title: sites[0], 
           zIndex: sites[3], 
           html: sites[4] 
          }); 

          var contentString = "Some content"; 

          google.maps.event.addListener(marker, "click", function() { 
           infowindow.setContent(this.html); 
           infowindow.open(map, this); 
          }); 
         } 
        } 
       </script> 
+0

我不明白你的問題。你想要像'map.setZoom(5)'這樣的東西嗎?或者根據國家設置不同的縮放比例? – mddw 2013-02-14 13:08:31

+0

[center on a country by google maps api v3]可能重複(http://stackoverflow.com/questions/4408397/center-on-a-country-by-name-google-maps-api-v3) – geocodezip 2013-02-14 14:14:48

回答

0

解決了這一問題,做更多的研究後發現了這個鏈接。

https://developers.google.com/maps/documentation/javascript/geocoding 

喬治

3

the documentation on the Geocoder,存在視和邊界,其中可用於中心和放大的結果地圖地址解析器的響應返回。

if (results && results[0] && results[0].geometry && results[0].geometry.viewport) 
     map.fitBounds(results[0].geometry.viewport); 

working example