Android maps show marker only at specific zoom level -


i want display locations of bus stations on google map. problem there lot , when zoom out gets messy. can't display markers above specific zoom level or make them resize map?

maybe it's not want, can you. worked me.

according tutorial created paul trebilcox ruiz in this web:

when map has lot of data points in small area, can cluttered user zooms out. not this, having many markers displayed @ once can cause devices slow down considerably.

in order alleviate of frustration caused these issues, can use google maps utils library animate markers clusters. first thing need create new model object implements clusteritem interface. model needs implement getposition method clusteritem interface in order return valid latlng object.

public class clustermarkerlocation implements clusteritem  {      private latlng position;       public clustermarkerlocation( latlng latlng )       {          position = latlng;      }       @override      public latlng getposition()       {          return position;      }       public void setposition( latlng position ) {          this.position = position;      }  } 

with model created, can create new activity called clustermarkeractivity , add manifest. when initialize map, need create clustermanager, associate googlemap, , add latlng positions clustermarkerlocations clustermanager utility know cluster. take @ implementation of initmarkers better understand how works.

private void initmarkers()  {      clustermanager<clustermarkerlocation> clustermanager = new clustermanager<clustermarkerlocation>( this, mgooglemap);      mgooglemap.setoncamerachangelistener(clustermanager);       double lat;      double lng;      random generator = new random();       for(int = 0; < 1000; i++)       {          lat = generator.nextdouble() / 3;          lng = generator.nextdouble() / 3;           if(generator.nextboolean())           {              lat = -lat;          }           if(generator.nextboolean())           {              lng = -lng;          }           clustermanager.additem( new clustermarkerlocation(new latlng( mcenterlocation.latitude + lat, mcenterlocation.longitude + lng)));      }  } 

in sample, create 1000 random points display , add them map. google maps utils library handles else us.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -