1

私はAndroidを初めて使用し、Androidエミュレーターで何かを試していました。ロケーションマネージャーとロケーションリスナーで遊んでいる間、エミュレーターを使用してロケーションを変更するコードをテストできました。locationlistenerは場所の変更をキャッチし、特定の場所に移動します。

プログラムを使用して同じテストを複製したいと思います。つまり、x秒ごとに(スレッドを介して)新しい座標をlocationlistenerに渡しますが、エミュレータではなくプログラムを介して渡します。

誰かがこの機能を実装する方法を提案できますか?

ネット上のどこかで見つけて試していたロケーションリスナーのコード:


private LocationListener locationListener;

private MapView mapView;
private MapController mc;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gps); 

    lm = (LocationManager) 
        getSystemService(Context.LOCATION_SERVICE);    

    locationListener = new MyLocationListener();

    lm.requestLocationUpdates(
        LocationManager.GPS_PROVIDER,0,0,locationListener);

    mapView = (MapView) findViewById(R.id.mpview);
    mc = mapView.getController();

}

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}        

private class MyLocationListener implements LocationListener 
{
    @Override
    public void onLocationChanged(Location locn) {
        if (locn != null) {                
            GeoPoint point = new GeoPoint(
                    (int) (locn.getLatitude() * 1E6), 
                    (int) (locn.getLongitude() * 1E6));
            mc.animateTo(point);
            mapView.invalidate();
        }
    }

    @Override
    public void onProviderDisabled(String provider) {

    }

    @Override
    public void onProviderEnabled(String provider) {

    }

    @Override
    public void onStatusChanged(String provider, int status, 
        Bundle extras) {

    }
}     

ありがとう!

4

0 に答える 0