Detect if camera is moving, then cancel the call of a function

For my maps, I’m calling an api function that’s return me json data.

This function calls an API every time the camera has stop moving (so I implement OnCameraIdleListener)

What I want is this :

  1. When the user stop moving the camera, it call the api.


  1. If the camera is moving right after, stop calling the first API call (in order to avoid the call of to much API).

Here’s my code :

    class MyMap: Fragment(), OnMapReadyCallback, GoogleMap.OnCameraIdleListener, GoogleMap.OnCameraMoveListener{
    override fun onCameraIdle() {
        val coords =
    private fun getStops(coordonnees : LatLng) {
//        Log.i(TAG, "$coordonnees")
        var url = Constants.url
        val longitude = coordonnees.longitude
        val latitude = coordonnees.latitude
        if(longitude != 0.0 && latitude != 0.0){
            val resultActus = Fuel.get(url).responseJson { request, response, result ->
                    json ->
                    parseStops(json.content) //this is my function to display marker and info window
                }, {
                    err ->
                    Log.i("error", err.toString())



As you can see, I’m using Fuel go get my data from the API.

What to I need to change to do what I want ? Can’t find the right topic about this…