2012-03-23 134 views

回答

1
protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.show3); 

     Dataset = (Gps_mapApplicationDataset) getApplicationContext(); 
     dbHelper = Dataset.getDbHelper(); 
     Dcalcuation = new DistanceCalculator(); 

     mapview = (MapView) findViewById(R.id.show_mapview); 
     mapview.setSatellite(false); 
     mapview.setBuiltInZoomControls(true); 
     mapOverlays = mapview.getOverlays(); 

     locMan = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 

     if (locMan.isProviderEnabled(LocationManager.GPS_PROVIDER)) { 
      locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, 100, 0, 
        this); 
      curLocation = locMan 
        .getLastKnownLocation(LocationManager.GPS_PROVIDER); 
      Log.v("Gps", "on"); 
     } else if (locMan.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { 
      locMan.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 
        100, 0, this); 
      curLocation = locMan 
        .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 
      Log.v("network", "on"); 

     } else { 
      Log.v("setting", "on"); 
      final Intent poke = new Intent(); 
      poke.setClassName("com.android.settings", 
        "com.android.settings.widget.SettingsAppWidgetProvider"); 
      poke.addCategory(Intent.CATEGORY_ALTERNATIVE); 
      poke.setData(Uri.parse("3")); 
      sendBroadcast(poke); 

      locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, 100, 0, 
        this); 
      curLocation = locMan 
        .getLastKnownLocation(LocationManager.GPS_PROVIDER); 
     } 

     if (curLocation != null) { 
      clat = curLocation.getLatitude(); 
      clng = curLocation.getLongitude(); 
      Log.v("TAG ", clat + " " + clng); 
      GeoPoint srcgeopoint = new GeoPoint((int) (clat * 1E6), 
        (int) (clng * 1E6)); 
      Drawable marker = getApplicationContext().getResources() 
        .getDrawable(R.drawable.pin1); 
      mapview.getController().animateTo(srcgeopoint); 
      MapAddressOverlay itemizedOverlay = new MapAddressOverlay(marker); 
      itemizedOverlay.addOverlay(this, clat, clng); 
      mapview.getOverlays().add(itemizedOverlay); 
      mapview.invalidate(); 

     } else { 
      Toast.makeText(new_map.this, "No Location Find", Toast.LENGTH_SHORT); 
     }