android - Google Maps API V2 addMarker and OnCameraChangeListener -


scenario

  • initial user position read , marker added + camera position set location.
  • each time user drags/zooms camera need call web service , pass rectangle coordinates of map. web service returns list of locations displayed markers within map's bounds.

so doing like:

oncreate

mmap.setoncamerachangelistener(new oncamerachangelistener() {     @override     public void oncamerachange(cameraposition cameraposition) {         // make web call locations         mytask = new mytask();         mytask.execute(); } 

on task onpostexecute each item returned web service make:

mmap.addmarker(     new markeroptions().position(         new latlng(mypoint.getlatitude(), mypoint.getlongitude())     )     .icon(bitmapdescriptorfactory.fromresource(r.drawable.ic_pushpin)) ); 

the expected behavior:: each time user scrolls or zooms, camera position changes , async task gets called again fresh batch of active coordinates

the actual behavior: infinite loop between onpostexecute , oncamerachangelistener.

from seems me, maybe wrong, addmarker triggers camera change event ? how can make expected behavior described above ?

from seems me, maybe wrong, addmarker triggers camera change event ?

no, doesn't. may want add full code other try solve puzzle.

the expected behavior:: each time user scrolls or zooms, camera position changes , async task gets called again fresh batch of active coordinates

why want fetch same data every time user changes camera position?

some considerations improve user experience:

  • getting data once , storing them sqlite db. of course if data changes, need sync them , require changing webservice bit. not download on simple user interface change.
  • keeping webservice communication outside activity context memoryleak-less solution. if have mytask inner class inside activity, keep destroyed activity in memory until task finishes.
  • only adding markers in visible region , not removing them if added. number of markers keep growing, better calling clear() every time user moves map. commonsware correctly suggests: less ipc better. can suggest android maps extensions. if don't use marker clustering, has option add markers dynamically, don't need write yourself.

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -