MapsActivity(Androidスタジオ)でユーザーの場所を取得する方法を説明したチュートリアルがインターネットで全面的に検索されました。しかし、私は見つけられませんでした、フォーラムでもいくつかの説明。MapsActivity AndroidStudioで現在地を取得する方法
これは私が欲しいものです:ユーザーが自分のアプリケーションのマップレイアウトを進めると、現在の場所が表示されます。
私はMapsActivity(Androidスタジオから)を作成し、私のマニフェストに適切な権限を設定しました。しかし、現在のユーザーの場所を取得するためにどのような機能を使用するのか、その機能を配置する場所はわかりません。以下は
はMapsActivityのコードです:
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
private GoogleApiClient client;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Paris and move the camera
LatLng paris = new LatLng(48.858930, 2.350831);
mMap.addMarker(new MarkerOptions().position(paris).title("Marker in Paris"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(paris));
}
}
はどうもありがとうございました!
試しましたか?あなたは[この回答](http://stackoverflow.com/questions/21403496/how-to-get-current-location-in-google-map-android)で書かれたように試すことができます! – iOSDeveloper
@iOSDeveloper受け入れられた答えは廃止されました。 api-23の場合、実行時にユーザーからLocation権限をリクエストする必要があります。[Android Mの現在の場所を表示するには、GoogleマップとLocationManagerを使用するにはどうすればよいですか?](http://stackoverflow.com/questions/ 34582370/how-can-i-use-google-maps-and-locationmanager-to-show-current-location-on-androi) –
ありがとうございました!できます :) –