foursquared

GPS を能動的に取りに行きますぜ的実装があると聞いて以下から取得。

hg 必要です。

備忘まで

とりあえず今使ってる TP edge E430 なうぶんつが HUAWEI な端末認識できないのでメモのみ残しておきます。動作検証は別途ってことで。
foursquared/main/src/com/joelapenna/foursquared/providers/GlobalSearchProvider.java の getBestRecentLocation というメソドの実装の動作確認がしたい。
定義が以下。

    /**
     * Convenience method for getting the most recent Location
     * 
     * @return the most recent Locations
     * @throws LocationException when no recent Location could be determined
     */
    private Location getBestRecentLocation() throws LocationException {
        BestLocationListener locationListener = new BestLocationListener();
        locationListener.updateLastKnownLocation((LocationManager) getContext().
            getSystemService(Context.LOCATION_SERVICE));
        Location location = locationListener.getLastKnownLocation();
        if (location != null) {
            return location;
        }
        throw new LocationException();
    }

呼び出して例外が戻ったらリトライ、というのが最適解なのかどうなのか。

もう少し

BestLocationListener クラスは foursquared/main/src/com/joelapenna/foursquared/location/ で定義されてます。つうか上で引用した getBestRecentLocation メソドが微妙に不思議なカンジなんですが、

  • インスタンス生成して
  • updateLastKnownLocation メソドに getSystemService(Context.LOCATION_SERVICE) 渡して
    • これって、同じアプリのどこかでこのクラスの register メソド呼び出して GPS 有効にしとくことで云々、なの?
    • register では isProviderEnabled であれば updateLocation を呼び出してますね
  • getLastKnownLocation メソドも戻りを、ナニ

という形になってますね。これを自分マターで呼び出してどんな形で位置情報が取得できるか、とか別途確認の方向ってことで。