OnCameraChangeListener is not responsive enough -

2019-04-11 10:50发布

I am porting a layer I have in a v1 map to v2. The layer draws a custom control on the map and, as the map moves, it must stay in place on its current geolocation (w/ the correct scale).

It had been suggested to me to use onCameraChange to communicate to my layer (a custom view, on top of the map) that the camera was panning or zooming and update the layer appropriately.

My problem is that onCameraChange is only called after the camera has been moved - not during. It is therefor not responsive enough. Is there another way to achieve this?

1条回答
霸刀☆藐视天下
2楼-- · 2019-04-11 11:09

Try to wrap the MapFragment (or MapView) inside your custom class inherited from something like RelativeLayout. Then you can override onInterceptTouchEvent or dispatchTouchEvent in that custom layout and move your custom view from there. I tried it myself and it will give you definitely more callbacks than with the onCameraChange.

You can also take a look at my answer here:
Google Maps Android API v2 - Interactive InfoWindow (like in original android google maps)
I was dealing with something little bit different (I tried to avoid moving custom views over the map but I needed only some buttons on an infoWindow), but I used this wrapping layout there too.

查看更多
登录 后发表回答