google maps api initial zoom error

前端 未结 1 521
抹茶落季
抹茶落季 2020-12-22 10:50

I have the following code:



//alert()



      function initial         


        
相关标签:
1条回答
  • 2020-12-22 11:21

    for some reason, when the map loads up, the zoom level is full, so its zoomed right into the marker.

    If you have a bounds object with one LatLng in it, it should zoom in as far as possible. From the documentation:

    fitBounds(bounds:LatLngBounds)  None    Sets the viewport to contain the given bounds.
    

    If you only have one marker, don't use fitBounds, use .setCenter (on the coordinates of the marker, .setZoom (to your desired zoom level).

    If your code needs to handle both cases (one marker or several markers), count the markers you add to the bounds, if the number is one use .setCenter/.setZoom, if it is more than one, use .fitBounds.

    0 讨论(0)
提交回复
热议问题