我正在使用LocationManager和LocationListener爲應用程序提供緯度和經度。在運行應用程序時,出現一個錯誤,提示「Sorry,Process system is not responding。」。這種情況發生在我通過DDMS下的仿真器控制或使用telnet命令提示手動提供lat和long時。無法烤麪包經緯度
Java代碼:
public class LocationFinder extends Activity {
private LocationManager locManager;
private LocationListener locListener;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
locManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locListener = new MyLocationListener();
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locListener);
}
private class MyLocationListener implements LocationListener{
@Override
public void onLocationChanged(Location loc) {
// TODO Auto-generated method stub
if(loc != null){
Toast.makeText(getBaseContext(), "Latitude: " + loc.getLatitude() + "Longitude: " + loc.getLongitude(), Toast.LENGTH_SHORT).show();
}
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
}
我也在模擬器也hw.gps在啓用的manifest.xml
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
以下權限。
我想知道我的代碼是否有問題。 感謝
不準確知道,但嘗試改變第一參數Toast.makeText()...到getApplicationContext()..... – Farhan 2011-04-27 12:54:24
移除MyLocationListener中的@Overrides是否有所作爲? – 2011-04-27 12:58:23