Android Google 地图 API v2:获取我的方位角位置
Android Google Maps API v2: get my bearing location
我想强制相机的行为就像您正在使用导航一样,这意味着当您向左旋转 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
。可以参考here.
另外,使用 CameraPosition
class here 调整相机位置。
编辑:我什至找到了更好的解决方案。在Locationclass中使用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));
}
我想强制相机的行为就像您正在使用导航一样,这意味着当您向左旋转 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
。可以参考here.
另外,使用 CameraPosition
class here 调整相机位置。
编辑:我什至找到了更好的解决方案。在Locationclass中使用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));
}