Android-需要在谷歌地图api 2上显示标记FOV

时间:2014-04-08 05:06:45

标签: android google-maps

我对android开发完全陌生。我正在使用Google map api 2,可以在地图上成功显示我的位置。现在我想显示我正在寻找的方向(即视野FOV, - 我的设备面向的方向),如本例所示。我将不胜感激任何帮助。对不起我的英文:)

enter image description here

enter image description here

图片参考:Dynamically drawing polygons in Google map

1 个答案:

答案 0 :(得分:1)

尝试为您的FOV使用GroundOverlay,此示例使用图像显示FOV:

private GroundOverlay mFovOverlay;
//** create the FOV **//
private void createFov(LatLng userPosition, GoogleMap map, float bearing) {

    GroundOverlayOptions fov = new GroundOverlayOptions();              
    fov.position(userPosition, 100f);
    fov.anchor(0.5f, 1f);
    fov.image(BitmapDescriptorFactory.fromResource(R.drawable.fov));                
    fov.bearing(bearing);
    mFovOverlay = map.addGroundOverlay(fov);

}

//** change the FOV direction **//
private void changeFovDirection(float bearing) {
    fovOverlay.setBearing(bearing);
}

如果要根据设备方向更改FOV方向,请以度为单位调用changeFovDirection。这里的方位是方位角,可以从设备传感器获得(见What is the alternative to android orientation sensor?)。请注意从弧度(传感器单位)转换为度数(GroundOverlay轴承单位),这是我在onSensorChanged方法中的代码片段:

float azimut = orientation[0]; // orientation contains: azimut, pitch and roll
float azimutDegrees = (float) (azimut * 180 / Math.PI);
mapFragment.changeFovDirection(azimutDegrees);
相关问题