@blog.justoneplanet.info

日々勉強

Fused Location Providerを試してみる

ライブラリのコピー。

cp ~/android-sdk-mac_x86/extras/google/google_play_services/libproject/google-play-services_lib/libs/* ./lib/

パーミッションの付加。

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

コード。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
    mLocationClient = new LocationClient(getApplicationContext(), this, this);
    mLocationClient.connect();
}
@Override
protected void onDestroy() {
    mLocationClient.disconnect();
    super.onDestroy();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public void onConnectionFailed(ConnectionResult result) {
}
@Override
public void onConnected(Bundle bundle) {
    Location location = mLocationClient.getLastLocation();
    android.util.Log.e("latitude", "" + location.getLatitude());
    android.util.Log.e("longitude", "" + location.getLongitude());
}
@Override
public void onDisconnected() {
}

参考

コメントはまだありません»

No comments yet.

RSS feed for comments on this post.TrackBack URL

Leave a comment