Google Maps JavaScript API - fitbounds together with setCenter

后端 未结 2 777
Happy的楠姐
Happy的楠姐 2021-01-14 06:55

I\'ve been looking around for a solution to this problem, but i can\'t seem to find somthing that solves this. The closest i get is this thread. But this doesn\'t work.

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-14 07:47

    The above answer didn't work for me. Here's what did:

    contained = true;
    map.fitBounds(bounds);
    map.setCenter(center);
    newbounds = map.getBounds();
    for (i = 0; i < l; i ++) {
      if (!newbounds.contains(markers[i].getPosition())) {
        contained = false;
      }
    }
    if (!contained) map.setZoom(map.getZoom() - 1);
    

提交回复
热议问题