react-google-maps: how to use fitBounds, panBy, panTo, panToBounds public APIs?

帅比萌擦擦* 提交于 2019-12-06 01:25:09

Looking at the function definition fitBounds(map, args) { return map.fitBounds(...args); } we can see that the spread operator is applied on args. That suggests that the args should be an array.

So, in your code the second parameter should be of an array type:

this._map.fitBounds(this._map, [this._bounds]);

You can also include the second element of the array that will be transformed into the second optional parameter padding of the Maps JavaScript API fitBound() method.

this._map.fitBounds(this._map, [this._bounds, 100]);

Hope this helps!

This is how you call panTo and fitBounds with react map ref

this.map.panTo({
  lat:e.latLng.lat(), lng: e.latLng.lng()
})
const bounds = new google.maps.LatLngBounds()
bounds.extend({
  lat:e.latLng.lat(), lng: e.latLng.lng()
})
this.map.fitBounds(bounds)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!