×

Discussion Board

Results 1 to 5 of 5

Hybrid View

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    1

    Question Map clustering on S40

    Hi,

    I develop S40 app which need to show big amount of points on map. The problem is in points' clustering. How do I implement it on Java ME?

    I want something like this: http://api.maps.nokia.com/en/playgro...ermarkers.html but on Java ME not web app.

    Thanks in advance

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,167

    Re: Map clustering on S40

    With Java, I don't think we have class like nokia.maps.clustering.ClusterProvider(), so you would propably need to construct this yourself. I would suppose it not being too easy to do, but would assume the idea would generally be to monitor zoom level changes, and then determine which items should be grouped.

    The grouping could be determined by checking the icon size in pixels, seeing how much that is in physical distance with current zoom level, and then checking what is the distance between the items. And then having a logic which determines when they should be grouped based on the values.

  3. #3
    Regular Contributor
    Join Date
    Aug 2011
    Location
    Berlin
    Posts
    288

    Re: Map clustering on S40

    The logic behind map clustering is relatively simple. Something like the following pseudo code would do:

    Code:
    Create cluster list.
    //For each marker within the current viewport ....
          for (int i= 0; index < markers.Count; i++)
                {
                      if (cluster nearby?){
                            add marker to nearest cluster.
                      } else {
                            create new cluster
                            add marker to cluster
                             add cluster to cluster list 
                      }
                      
                }
    return cluster list;
    As well as holding an array of associated markers, any cluster needs two further properties - a center point and a radius.
    The simplest way to set a centre point would be to use the location of the first marker in the cluster.
    The distances should really be related to the viewport size i.e the distance between the
    The "nearby" bit can be done using the Haversine formula ie. Geocordinate.distanceTo()


    The reason there is no MapComponent providing clustering on the device is due to the limits of the Java ME environment. It doesn't make sense to hold the information about 10,000 markers on a device and it is very likely to run out of memory.

    Your best bet would be to look at server side clustering. You could create a MapComponent that overrides mapUpdated so that when the viewport changes it makes a request to a server passing back the coordinates of the viewport. The server would then return the details of the markers within the viewport using clustering as necessary in the form of an XML or JSON file. As a refinement I'd suggest loading a slighltly larger area than the viewport so you only need to make another server request if the user has panned out of area (or altered the zoom.)

    If you can move the computations server side, the Maps API is reduced to being a presentation layer, which is the job it does best.


    Code:
    public  abstract class ClusterComponent implements MapComponent {
    
    ...
        protected MapDisplay map;
     private double thresholdDistance;
    
     public void attach(MapDisplay map) {
          this.map = map;
            radius= map.getCenter().distanceTo(
                    map.pixelToGeo(
                            new Point(map.getWidth(), map.getHeight())));
        }
    
        // from MapComponent
        public void mapUpdated(boolean zoomChanged) {
            mapUrl = getMapURL(map);
    
            if (zoomChanged || map.getCenter().distanceTo(coord) > radius/2) {
               //map.getCenter();
               // radius= map.getCenter().distanceTo(
               //         map.pixelToGeo(
               //                 new Point(map.getWidth(), map.getHeight())));
               
              // 1) Create new thread....
              // 2) Make Server request passing in centerpoint and radius...
              // 3) When received clear all points and re-add markers.
              // etc.
            }
        }
    Last edited by jasfox; 2012-12-04 at 10:43.

  4. #4
    Registered User
    Join Date
    Jan 2009
    Location
    Melbourne, Australia
    Posts
    2,571

    Re: Map clustering on S40

    Quote Originally Posted by jasfox View Post
    The logic behind map clustering is relatively simple. Something like the following pseudo code would do:
    Hi Jason

    Is there a wiki article on this, and if not, could you create one?

    Regards
    Hamish

  5. #5
    Regular Contributor
    Join Date
    Aug 2011
    Location
    Berlin
    Posts
    288

    Re: Map clustering on S40

    I've created a stub for wiki article here: http://www.developer.nokia.com/Commu...PI_for_Java_ME .
    I've added two "toy" example coded examples loading asynchronous XML marker data which demonstrate the ideas behind marker clustering. I haven't written the commentary as yet.
    Neither example would have any practical use though, as they do not scale and they slow down exponentially as the number of markers increases.
    The commentary and examples really need to include information on server side clustering to be of much use in a real world application.

    There is a simple PERL script described in the book below which explains how to obtain clustered XML data from a source file
    http://books.google.com/books?id=-np...20perl&f=false
    This is the source file: http://mappinghacks.com/projects/gmaps/cluster_data.txt
    This is the clustered XML data endpoint: http://mappinghacks.com/projects/gma...1&size=240+100

    The coded example could be altered to asynchronous load XML from the server which would reduce calculations on the device.
    The other bottleneck I've found is the time taken to render each marker on the emulator. If this is a problem on the device, the obvious answer would be to load the whole cluster data as an overlay.

Similar Threads

  1. clustering.ITheme and clustering.MarkerTheme for ClusterProvider
    By upixsoul in forum [Archived] Maps API for Javascript
    Replies: 5
    Last Post: 2012-10-16, 16:07
  2. nokia.maps.clustering.ClusterProvider and dataPoints? IClusterPoint?
    By upixsoul in forum [Archived] Maps API for Javascript
    Replies: 3
    Last Post: 2012-10-12, 16:28
  3. Clustering on distance matrix
    By mrjayaram in forum Mobile Java General
    Replies: 0
    Last Post: 2010-07-21, 15:43
  4. Clustering on data matrix
    By mrjayaram in forum Mobile Java General
    Replies: 0
    Last Post: 2010-07-14, 12:42

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×