goobnoob wrote:
> I have a simple application in mind where I would like to zoom the map
> to show a collection of nearby points on a map.  Is there a way to
> tell the map to zoom to show a range of lats longs, or a collection of
> locations?
>
> goob
> >
>
>   
This is some code that pull group of location on to a screen so that you 
can see then all

package com.cyberspace.location;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import com.cyberspace.location.db.DbHelper;
import com.cyberspace.location.db.Waypoint;
import com.google.android.maps.Overlay;


import com.google.android.maps.Point;
import com.google.googlenav.map.MapPoint;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


public class LocationOverlay extends Overlay {

   
   
    private List<Waypoint> entries;
    private DbHelper dbHelper;
    WhatsAroundMe whatsAroundMe;
    private Paint paint1 = new Paint();
    private Paint paint2 = new Paint();

   
     // Minimum & maximum latitude so we can span it
     // The latitude is clamped between -80 degrees and +80 degrees 
inclusive
     // thus we ensure that we go beyond that number
     private int minLatitude = (int)(+81 * 1E6);
     private int maxLatitude = (int)(-81 * 1E6);
    
     // Minimum & maximum longitude so we can span it
     // The longitude is clamped between -180 degrees and +180 degrees 
inclusive
     // thus we ensure that we go beyond that number
     private int minLongitude  = (int)(+181 * 1E6);
     private int maxLongitude  = (int)(-181 * 1E6);
   
   
   
   
    public LocationOverlay(WhatsAroundMe whatsAroundMe) {
        this.whatsAroundMe = whatsAroundMe;
        dbHelper = new DbHelper(whatsAroundMe);
      //  paint1.setARGB(255, 255, 255, 255);
    }

   
   
   
    @Override
    public void draw(Canvas canvas, PixelCalculator pixelCalculator, 
boolean b) {
        super.draw(canvas, pixelCalculator, b);
    
                List<Point> mPoints = new ArrayList<Point>(); 
                entries = dbHelper.fetchAllRows();
               
       
        for(int i = 0; i<entries.size(); i++)
        {
                int[] screenCoordsAll = new int[2];
               
                Double latitude =  Double.valueOf(entries.get(i).xCoord) 
* 1E6;
                Double longitude = Double.valueOf(entries.get(i).yCoord) 
* 1E6;
               
               
               
                if (latitude.intValue() != 0 && longitude.intValue() !=0)  {
                    minLatitude = (minLatitude > latitude.intValue()) ? 
latitude.intValue() : minLatitude;
                    maxLatitude = (maxLatitude < latitude.intValue()) ? 
latitude.intValue() : maxLatitude;     
                   
                    // Sets the minimum and maximum latitude so we can 
span and zoom
                    minLongitude = (minLongitude > longitude.intValue()) 
? longitude.intValue() : minLongitude;
                    maxLongitude = (maxLongitude < longitude.intValue()) 
? longitude.intValue() : maxLongitude;
                   
                    mPoints.add(new Point(latitude.intValue(), 
longitude.intValue()));
                }
               
                MapPoint point = new MapPoint(latitude.intValue(), 
longitude.intValue());
                MapPointToScreenCoords(point, 
screenCoordsAll,pixelCalculator);
             
                canvas.drawCircle(screenCoordsAll[0], 
screenCoordsAll[1], 9, paint1);
            
        }      
       
        whatsAroundMe.mc.zoomToSpan((maxLatitude - minLatitude),
                    (maxLongitude - minLongitude));
       
        //TODO work on zoom in and out
       
       
        whatsAroundMe.mc.animateTo(new Point(
                     (maxLatitude + minLatitude)/2,
                     (maxLongitude + minLongitude)/2 ));
      }
  
   
   private void MapPointToScreenCoords(MapPoint mp, int[] 
targetScreenCoords, PixelCalculator pxc){
        Point p = new Point(mp.getLatitude(), mp.getLongitude());
        pxc.getPointXY(p, targetScreenCoords);
               // whatsAroundMe.mc.animateTo(p);
    }
 
  


}
Peter
       


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to