1

ユーザーが地図上の住所を選択する簡単な場所のリマインダーを作成し、それを使用してproximityAlertを作成しています。

最初に考えたのは、その時間内に目的地に到着できる場合にのみ、新しい場所を探すことでした。ターゲットが 80 マイル離れている場合、車で到達するのに約 1 時間かかるため、常に場所を照会しても意味がありません。ここ で、運転中にのみ位置情報の更新を取得する別のアプローチを見つけました。

  1. この 2 つのアプローチについて意見を求めたいと思います。これは、proximityAlert を使用するよりもバッテリー寿命を本当に節約できますか?
  2. これらの計算を自分で行う場合、独自のバージョンの proxyAlert() を実装する必要がありますか?
  3. ロケーションの更新を受け取る LocationIntentService は別のクラスです。ロケーション クライアントにアクセスして、removeUpdates や requestLocationUpdates を取得するにはどうすればよいですか?
  4. 位置情報の更新を起こすには、AlarmManager を使用する必要がありますか?

私は onHandleIntent() メソッドにかなり行き詰まっています。そこで何をすべきかわかりません。どんな入力でも嬉しいです

    public class MyMapActivity extends Activity implements OnInfoWindowClickListener, 
       OnMarkerClickListener, OnMapLongClickListener, 
       GooglePlayServicesClient.ConnectionCallbacks,
       GooglePlayServicesClient.OnConnectionFailedListener
    {

       private LocationClient mLocationClient;
       private PendingIntent mPendingIntent = null;
       private LocationRequest mLocationRequest = LocationRequest.create()
          .setInterval(5000)         // 5 seconds
          .setFastestInterval(16)    // 16ms = 60fps
          .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);


       @Override
   protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_gmaps);

            mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
            map.setMyLocationEnabled(true);
            map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
            map.setInfoWindowAdapter(new MyInfoWindowAdapter(this, getLayoutInflater()));
            map.setOnMapLongClickListener(this);
            map.setOnInfoWindowClickListener(this);
            map.setOnMarkerClickListener(this);
            String locationProvider = findBestLocationProvider();
            if(locationProvider != null) {
                  mMyLocation = mLocationManager.getLastKnownLocation(locationProvider);
            }
            Intent intent = new Intent( getApplicationContext(), LocationIntentService.class);
            intent.putExtra(LOCATION_KEY, mMyLocation);
            mPendingIntent = PendingIntent.getService(getApplicationContext(), 0, intent,              PendingIntent.FLAG_UPDATE_CURRENT);
       }

       @Override
       public void onConnected(Bundle arg0) {
            Log.d(TAG, "onConnected()");
            if(mLocationClient != null) {
                mLocationClient.requestLocationUpdates(mLocationRequest, mPendingIntent);
            }
       }

       @Override
       public void onDisconnected() {
            Log.d(TAG, "onDisconnected()");
       }
    }

サービス:

  public class LocationIntentService  extends IntentService {

     private Location mLocation = null;

     @Override
     protected void onHandleIntent(Intent intent) {
         Log.d(tag, "caught an intent");

         if(intent.hasExtra(MyMapActivity.LOCATION_KEY)) {
         Location loc = (Location) intent.getExtras().get(MyMapActivity.LOCATION_KEY);
         Log.d(tag, "onHandleIntent(): new location: " + loc.toString());

           // do calculation here.
           // how would I get access to the location client to removeUpdates and/or requestLocationUpdates
          // remove locationUpdates and start Alarm to start locationUpdates in X minutes
         mLocation = loc;
        }
     }
4

0 に答える 0