2013-02-14 120 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