Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 25th, 2012  |  syntax: None  |  size: 3.18 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Can't succed to write in a database
  2. public class screen4 extends MapActivity
  3. {    
  4.     private LocationManager lm;
  5.     private LocationListener locationListener;
  6.     private MyLocationOverlay myLocOverlay;
  7.  
  8.     private MapView mapView;
  9.     private MapController mc;
  10.  
  11. List<GeoPoint> geoPointsArray = new ArrayList<GeoPoint>();
  12.     int latitude;
  13.     int longitude;
  14.  
  15.     @Override
  16.     public void onCreate(Bundle savedInstanceState) {
  17.         super.onCreate(savedInstanceState);
  18.         setContentView(R.layout.screen4);
  19.         lm = (LocationManager)
  20.             getSystemService(Context.LOCATION_SERVICE);    
  21.  
  22.         locationListener = new MyLocationListener();
  23.  
  24.         lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locationListener);
  25.  
  26.         mapView = (MapView) findViewById(R.id.mapview1);
  27.         mapView.setBuiltInZoomControls(true);
  28.         mc = mapView.getController();
  29.         initMyLocation();
  30.        DBAdapter db=new DBAdapter(this);
  31.        db.createDatabase();
  32.        db.openDataBase();
  33.       for (int i = 0; i < geoPointsArray.size()-1; i++)
  34.        {
  35.            GeoPoint loc=geoPointsArray.get(i);
  36.  
  37.           db.insertData(Integer.toString(loc.getLongitudeE6()),Integer.toString(loc.getLatitudeE6()),null,null,null);
  38.  
  39.  
  40.        }
  41.       Cursor c=db.getAllData();
  42.      if(c.moveToFirst())
  43.      {
  44.       do{
  45.           DisplayTitle(c);
  46.       }while(c.moveToNext());
  47.  
  48.      }
  49.      if(c!=null&&!c.isClosed()){
  50.         db.close();
  51.      }
  52.  
  53.     }
  54.  
  55.     private void initMyLocation() {
  56.         myLocOverlay = new MyLocationOverlay(this, mapView);
  57.         myLocOverlay.enableMyLocation();
  58.         mapView.getOverlays().add(myLocOverlay);
  59.  
  60.     }
  61.     public void DisplayTitle(Cursor c)
  62.     {
  63.         Toast.makeText(this,
  64.                 "longitude: " + c.getString(0) + "n" +
  65.                 "latitude: " + c.getString(1) + "n",
  66.                 Toast.LENGTH_LONG).show();        
  67.     }
  68.     private class MyLocationListener implements LocationListener
  69.     {
  70.         @Override
  71.         public void onLocationChanged(Location loc) {
  72.             if (loc != null) {                        
  73.                 latitude=(int) (loc.getLatitude()* 1E6);
  74.                 longitude=(int) (loc.getLongitude()* 1E6);
  75.  
  76.  
  77.  
  78.            GeoPoint p = new GeoPoint(latitude,longitude);
  79.            geoPointsArray.add(p);
  80.  
  81.                 mc.animateTo(p);
  82.               mc.setZoom(17);                
  83.                 mapView.invalidate();
  84.                 mapView.setSatellite(true);
  85.            }
  86.  
  87.         }
  88.  
  89.         @Override
  90.         public void onProviderDisabled(String provider) {
  91.             // TODO Auto-generated method stub
  92.         }
  93.  
  94.         @Override
  95.         public void onProviderEnabled(String provider) {
  96.  
  97.         }
  98.         @Override
  99.         public void onStatusChanged(String provider, int status, Bundle extras) {
  100.  
  101.         }
  102.     }
  103.  
  104.     protected boolean isRouteDisplayed() {
  105.         // TODO Auto-generated method stub
  106.         return false;
  107.     }
  108.  
  109.      }
  110.        
  111. for (int i = 0; i < geoPointsArray.size()-1; i++)
  112.        {
  113.            GeoPoint loc=geoPointsArray.get(i);
  114.            db.insertData(Integer.toString(loc.getLongitudeE6()),Integer.toString(loc.getLatitudeE6()),null,null,null);
  115.        }
  116.        
  117. for (GeoPoint loc : geoPointsArray) {
  118.     ....