ナビゲーションを使用しているようにカメラを強制的に動作させたいと思います。つまり、左に90度回転すると、カメラは同じことを行います。
私の場所(青い点として)が表示されているGoogleマップがあります。
mGoogleMap.setMyLocationEnabled(true);
私が動いているとき、青い点は私の現在の方位を示す矢印です。このベアリングを手に入れたいです。
FusedLocationApiを使用して現在地を取得しています:
currentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
以下のコードは、カメラを現在の場所にアニメーション化していますが、方位はありません。ベアリングを追加することはできますが、値がわかりません。
@Override
public void onLocationChanged(Location location) {
LatLng latLng = new LatLng( location.getLatitude(), location.getLongitude() );
mGoogleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mGoogleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
}
現在地の方向を取得する方法を知っていますか?それについての適切な情報を見つけることができませんでした。私はあなたが私に与えることができるどんな助けでも大いに感謝します。
ありがとうございました
を使用してgetOrientation(R, orientation)
(そして真北に合わせて)試してみることができると思いますget the device rotation
。あなたは、参照することができますここで。
また、ここのCameraPosition
クラスを使用してカメラの位置を調整します。
編集:私はさらに良い解決策を見つけました。LocationクラスのgetBearing()
メソッドを使用します。
if (location.hasBearing()) {
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(latLng) // Sets the center of the map to current location
.zoom(15) // Sets the zoom
.bearing(location.getBearing()) // Sets the orientation of the camera to east
.tilt(0) // Sets the tilt of the camera to 0 degrees
.build(); // Creates a CameraPosition from the builder
mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加