使用LocationManager类,得到当前位置

public GeoPoint getCurrenLocation() {
  LocationManager locationManager;
  String context = Context.LOCATION_SERVICE;
  locationManager = (LocationManager) this.mapView.getContext()
    .getSystemService(context);//实例化
  Criteria criteria = new Criteria();
  criteria.setAccuracy(Criteria.ACCURACY_FINE);
  criteria.setAltitudeRequired(false);
  criteria.setBearingRequired(false);
  criteria.setCostAllowed(true);
  criteria.setPowerRequirement(Criteria.POWER_LOW);
  String provider = locationManager.getBestProvider(criteria, true);
  Location location = locationManager.getLastKnownLocation(provider);

  GeoPoint currnentGeoPoint = new GeoPoint((int) (23.127614 * 1000000),
    (int) (113.367704 * 1000000));
  if (location != null) {
   double latitude = location.getLatitude();
   double longitude = location.getLongitude();
   currnentGeoPoint = new GeoPoint((int) (latitude * 1E6),
     (int) (longitude * 1E6));
  }
  updateWithNewLocation(currnentGeoPoint);
  locationManager.requestLocationUpdates(provider, 2000, 10, locationListener);

  return currnentGeoPoint;
 }

你可能感兴趣的:(String,null)