How to get Google Maps API to set the correct zoom level for a country?

后端 未结 4 630
长情又很酷
长情又很酷 2020-11-28 02:30

Is there a was of automatically setting the zoom level based on the size of the country that the map has been centered on?

maps.google.com does exactly what I need,

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 03:19

    For V3 this code worked for me:

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

提交回复
热议问题