Google Maps OnCameraChanged Function. How can I slow it down?


#1

Hello,

This is probably more of a general javascript function than plugin specific.

I am using the onCameraChanged function to grab the bounds of the map window and hit an api to populate markers on the map. What I am seeing is if I slow drag the whole map the onCameraChanged function is getting called a bunch of times in a very short period of time.

What would be a good way to prevent the multiple calls from happening?

I was thinking I could create a variable called isBusy, the first time the onCameraChanged function is run it would set isBusy=true. When when finished it would set isBusy = false. If the onCameraChanged function is called again while the first one is still running it would see isBusy is true and stop.

is there a better way to handle this in Javascript?

Thank You,

Randy


#2

Since I didn’t hear anything on this I went ahead and gave my idea a try. It seems to work just fine. I put a sleep() function in the server side API call to slow the response down a few seconds and was able to test.


#3

Hi randy, I’m using google maps too. I’m trying to center the map, is there a method? I have binded the location data to the view but it seems that the maps takes that data only when the page is loaded , I don’t know why…And also do you know how can I move an already existing marker?
Sorry for all these questions


#4

I will need to research how to center the map.

If you need to move the marker remove the marker first and then re-add it.

The demo app has a removeMarker example:

There is also a remove all markers function:

  mapView.removeAllMarkers();