First off, created 4 int variables:
Using java Syntax Highlighting
- // 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);;
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
I created a function to setup the map:
Using java Syntax Highlighting
- /*
- * Basic Map setup
- */
- private void setupMap(){
- // Holds all the picture location as Point
- List<Point> mPoints = new ArrayList<Point>();
- while (mCursor.next()) {
- //You get the latitude/longitude as you want, here I take it from the db
- int latitude = mCursor.getInt(LATITUDE_INDEX);
- int longitude = mCursor.getInt(LONGITUDE_INDEX);
- // Sometimes the longitude or latitude gathering
- // did not work so skipping the point
- // doubt anybody would be at 0 0
- if (latitude != 0 && longitude !=0) {
- // Sets the minimum and maximum latitude so we can span and zoom
- minLatitude = (minLatitude > latitude) ? latitude : minLatitude;
- maxLatitude = (maxLatitude < latitude) ? latitude : maxLatitude;
- // Sets the minimum and maximum latitude so we can span and zoom
- minLongitude = (minLongitude > longitude) ? longitude : minLongitude;
- maxLongitude = (maxLongitude < longitude) ? longitude : maxLongitude;
- mPoints.add(new Point(latitude, longitude));
- }
- }
- // Get the controller
- mMapController = mMapView.getController();
- // Zoom to span from the list of points
- mMapController.zoomToSpan(
- (maxLatitude - minLatitude),
- (maxLongitude - minLongitude));
- // Animate to the center cluster of points
- mMapController.animateTo(new Point(
- (maxLatitude + minLatitude)/2,
- (maxLongitude + minLongitude)/2 ));
- // Add all the point to the overlay
- mMapOverlay = new MyPhotoMapOverlay(mPoints);
- mMapOverlayController = mMapView.createOverlayController();
- // Add the overlay to the mapview
- mMapOverlayController.add(mMapOverlay, true);
- }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
That is about it. I will not go into details of the overlay and mapView setup etc... But this should help out on zooming and spanning to the correct level and position.
./C






