0

ねえ、私は現在、携帯電話のGPS位置情報と一緒にAndEngineを使用する方法を調べています。この情報にアクセスするのはそれほど難しくないはずだと思ったので、ChangeableTextの例を取得し、それを微調整して、場所を正しく取得していることを確認しようとしています。基本的には、次のようにします。

クラス宣言に「implementsLocationListener」を追加しました

    public class ChangeableTextExample extends BaseExample implements LocationListener{

クラスフィールドにロケーション変数とロケーションマネージャを追加しました。

private long curlat;
private long curlng;
private LocationManager locationManager;

onLoadScene()メソッドでlocationManagerをインスタンス化しました。

locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

経過したテキストを設定して、curlat変数とcurlng変数を出力します。

     scene.registerUpdateHandler(new TimerHandler(1 / 20.0f, true, new ITimerCallback() {
        public void onTimePassed(final TimerHandler pTimerHandler) {
            elapsedText.setText("Location: " + curlat + ", " + curlng);
            fpsText.setText("FPS: " + fpsCounter.getFPS());
        }
    }));

そして、onLocationChanged(Location arg)メソッドを実装して、curlat、curlngフィールドを更新します。

public void onLocationChanged(Location location) {
    this.curlat = (long) (location.getLatitude()*1E6);
    this.curlng = (long) (location.getLongitude()*1E6);     
}

悲しいことに、これはうまくいきません、そしてあなたの誰かが私を正しい方向に向けることができるかどうか疑問に思いましたか?私はAndroid向けのプログラミングにかなり慣れておらず、AndEngineを使ったプログラミングにも慣れていません。locationManagerが適切にインスタンス化されていないという事実と関係があると思いますか?

ありがとう!

4

2 に答える 2

1

Android-ユーザーの場所の取得を参照してください。

実際にlocationManagerオブジェクトに更新を提供するように指示する必要があります(また、位置情報についてはAndroidManifest.xmlにアクセス許可を設定する必要があります)。

リンクから、あなたが見逃しているものは次のとおりです。

// Register the listener with the Location Manager to receive location updates
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);

AndroidManifest.xmlの場合(GPSの代わりに精度の低いネットワーク/ Wi-Fiロケーションのものだけを使用したい場合は、アクセス許可を変更する必要がある場合があります):

<manifest ... >
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    ...
</manifest>
于 2011-03-11T17:41:25.863 に答える
1

Btw, you can use enableLocationSensor of the Engine/BaseGameActivity class to let AndEngine manage the location-retrieval for you.

于 2011-06-20T11:15:29.937 に答える