1

いつものように新しい場所を取得しますか? onCreateここでこのコードを使用しています

        locationManager = (LocationManager) this.getSystemService(LOCATION_SERVICE);
        isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
        isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
               if (isGPSEnabled) {
                      if (location == null) {
                          provider = LocationManager.GPS_PROVIDER;
                          locationManager.requestLocationUpdates(provider, 500, 0, this);
                          if (locationManager != null) {
                              location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);                                                    
                              if (location != null) {
                                  latLng = new LatLng(location.getLatitude(), location.getLongitude());                                   
                                  if (location != null) {                                                                                                             
                                      ParseQueryMap();
                                  }
                              }
                          }
                       }
                     }                            
              if (isNetworkEnabled){ 
                       if (location == null) {
                       provider = LocationManager.NETWORK_PROVIDER;
                       locationManager.requestLocationUpdates(provider, 500, 0, this);
                       if (locationManager != null) {                   
                           location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);       
                           if (location != null) {
                               latLng = new LatLng(location.getLatitude(), location.getLongitude());                               
                               if (location != null) {  
                                   ParseQueryMap();                               
                               }
                            }
                         }
                       }
                     }
                }

アプリケーションを実行したときにその場所が利用できない場合、以前に知られていた場所 ( getLastKnownLocation()) が使用されます。私はこの解決策が好きではありません。すぐに、または一定時間 (約 5 秒) 後にアプリケーションを実行して、正確な位置を表示する必要があります。起動時の正確な位置は、ベースの最も近いポイントを表示する必要があります。出来ますか?助けてくれてありがとう

4

1 に答える 1

1

パッシブ ロケーション プロバイダーを試してください。これを使用することで、位置情報の更新を既に要求している他のアプリと一緒に受け取ることができます。

場所をできるだけ早く修正する方法について詳しく説明しているこのブログ エントリを参照してください。サンプル コードはandroid-protips-locationプロジェクトにあります。

于 2013-04-16T13:20:01.640 に答える