2017-02-13 20 views

回答

0

你可以使用的LocationManager

LocationManager locationManager = (LocationManager) getSystemService(getApplicationContext().LOCATION_SERVICE); 
    // default 
    Criteria criteria = new Criteria(); 

    String provider = locationManager.getBestProvider(criteria, false);//get bese location provider 

    if (provider != null && !provider.equals("")) 
    { 

     //check for permission 
       if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { 
      // Get the location from the given provider 
      Location location = locationManager.getLastKnownLocation(provider); 

      if (location != null) { 

       String Latitude = "" + location.getLatitude(); 
       String Longitude = "" + location.getLongitude(); 
      } 

     } 
} 

您需要權限