Bartos
Bartos

Reputation: 1037

Android Maps, how to check scroll length

In my app I'm using Google maps. I refresh data from API every time onCameraIdle() is being called. I know it's not good solution. My question is - can I detect if user swiped more than half of visible region and only then load data ? I don't know if my question is clear, if not , let me know, I will try to write it more precisely. Thank you!

Upvotes: 0

Views: 66

Answers (1)

Henrique
Henrique

Reputation: 882

You can use the projection visible region and the camera target to achieve what you want:

cameraTarget = map.cameraPosition.target
when (viewPort?.contains(cameraTarget)) {
    true -> {
        // Did not scroll more than half (camera center still inside initial bounds)
    }
    false -> {
        // Scrolled more than half (camera center outside initial bounds)
    }
}
viewPort = map.projection.visibleRegion.latLngBounds

Upvotes: 2

Related Questions