Android での gps の実装に問題があります。問題は GPS ロストフィックスです。位置アイコンが点滅し、数秒後に位置がトースト表示され、GPS が修正を失い、再度接続を試みます。
私のサービス:
public class LocationService extends Service {
private static final long MIN_TIME = 15000;
private static final float MIN_DISTANCE = 1;
private final IBinder binder = new LocalBinder();
private LocationManager locationManager;
@Override
public void onCreate() {
super.onCreate();
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
}
@Override
public IBinder onBind(Intent intent) {
return binder;
}
public class LocalBinder extends Binder {
LocationService getService() {
return LocationService.this;
}
}
public void setListener(LocationListener listener) {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME, MIN_DISTANCE, listener);
}
public void removeListener(LocationListener listener) {
locationManager.removeUpdates(listener);
}
}
私の活動:
public class MainMapActivity extends CustomMapActivity implements LocationListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_layout);
Intent i = new Intent(this, LocationService.class);
startService(i);
bindService(i, conn, BIND_AUTO_CREATE);
}
@Override
public void onDestroy() {
super.onDestroy();
unbindService(conn);
}
ServiceConnection conn = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
// TODO Auto-generated method stub
serv = ((LocalBinder)service).getService();
serv.setListener(MainMapActivity.this);
}
};
@Override
public void onLocationChanged(Location location) {
Toast.makeText(this, Double.toString(location.getLatitude())+Double.toString(location.getLongitude()), Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}
Google マップ アプリでは完璧に動作するため、デバイスの問題ではありません。
手伝ってくれてありがとう