你好我在私人APN连接的Android手机上有一个应用程序我想知道如果我无法导航到我的APN上没有的任何地方,我可以获得GPS位置。
这是在我的应用上使用GPS的代码:
public double[] _getLocation (Context _context)
{
// Get the location manager
LocationManager locationManager = (LocationManager)_context.getSystemService (LOCATION_SERVICE);
Criteria criteria = new Criteria ();
String bestProvider = locationManager.getBestProvider (criteria, true);
Location location = locationManager.getLastKnownLocation (bestProvider);
LocationListener loc_listener = new LocationListener() {
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
};
locationManager.requestLocationUpdates(bestProvider,0 ,0, loc_listener);
location = locationManager.getLastKnownLocation (bestProvider);
double lat=0.00;
double lon=0.00;
try
{
lat = location.getLatitude ();
lon = location.getLongitude ();
}
catch (NullPointerException e)
{
Toast.makeText(_context,"El GPS debe estar encendido, asegurate en configuracion-->Localizacion",Toast.LENGTH_LONG).show();
}
double[] result = {lat,lon};
return result;
}