1

私のプロジェクトで必要なため、私の現在の場所を取得するには、アンドロイドアプリケーションにgoogle play apiを追加しました。Google Playサービスが遅いです。

現在の場所を取得するために必要なコードを追加した後は問題なく動作しますが、ボタンをクリックして20-25秒後に応答します。

もっと速くする方法はありますか? GPS_PROVIDERを使用して

.... 
    LocationManager myManager; 
    MyLocListener loc; 
    loc = new MyLocListener(); 
    myManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); 
    if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 
     // TODO: Consider calling 
     // ActivityCompat#requestPermissions 
     // here to request the missing permissions, and then overriding 
     // public void onRequestPermissionsResult(int requestCode, String[] permissions, 
     //           int[] grantResults) 
     // to handle the case where the user grants the permission. See the documentation 
     // for ActivityCompat#requestPermissions for more details. 
     return; 
    } 
    myManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, loc); 
} 

public class MyLocListener implements LocationListener { 

    @Override 
    public void onLocationChanged(Location location) 
    { 
     if(location != null) 
     { 
      // it logs after 20-25 s 
      Log.d("Latitude :", "" + location.getLatitude()); 
      Log.d("Latitude :", "" + location.getLongitude()); 
     } 
    } 

    @Override 
    public void onProviderEnabled(String provider) { 

    } 

    @Override 
    public void onProviderDisabled(String provider) { 
    } 

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

} 
+2

あなたは[FusedLocationProviderApi](https://developers.google.com/android/reference/com/google/android/gms/location/FusedLocationProviderApi)などのGoogle PlayサービスAPIを使用していません。 – ianhanniballake

+0

私はGoogleのサービスを初めて使いこなすのですが、FusedLocationProviderApiが何をできるのか説明してください。 –

答えて

3

一般的にハードウェアに応じて10〜30秒かかるん厳格なGPSの修正が必要:

は、ここに私のコードです。

Receiving location updates training pageに記載されているように、FusedLocationProviderApiを使用することを検討する必要があります。この情報は、Wi-Fi、Bluetooth、GPSなどのさまざまなソースからの位置情報を組み合わせています。

+0

恐ろしいですが、これを使って既存のアプリ(github ...)を共有してテストすることができますか? –

+1

@AbdenaceurLichiheb - 私の答えでリンクしたトレーニングページの[サンプル](https://github.com/googlesamples/android-play-location/tree/master/LocationUpdates)へのリンクがあります。 – ianhanniballake

+0

ありがとう、私はもっと感謝することはできません。 –

関連する問題