我尝试通过这种方式获取我的位置:
public void onCreate(Bundle savedInstanceState) {
LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 5, mlocListener);
}
public class MyLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location loc) {
latitude = loc.getLatitude();
longitude = loc.getLongitude();
Toast.makeText(getApplicationContext(), "Location found", Toast.LENGTH_SHORT ).show();
}
@Override
public void onProviderDisabled(String provider) {
Toast.makeText(getApplicationContext(), "GPS disabled", Toast.LENGTH_SHORT ).show();
}
@Override
public void onProviderEnabled(String provider) {}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {}
}
以下是我的权限:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
当我尝试使用我的Eclipse模拟器时,这非常有效,Toast出现了。 但在我的HTC One X上,它永远不会出现...... 你知道为什么吗? 感谢。