0

I am completely new to android development. I'm working with Google map api 2 and can successfully show my position on the map. Now I want to show direction where i'm looking (i.e. field of view FOV, - the direction my device facing)as shown on this example. I would appreciate any help. Sorry for my English :)

enter image description here

enter image description here

Image References : Dynamically drawing polygons in Google map

Community
  • 1
  • 1

1 Answers1

1

Try using a GroundOverlay for your FOV, this sample uses an image to show the 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);
}

If you want to change the FOV orientation according to the device orientation, call changeFovDirection with the bearing in degrees. The bearing here is the azimuth angle which can be obtained from the device sensors (see What is the alternative to android orientation sensor?). Notice to convert from radians (the sensor units) to degrees (the GroundOverlay bearing units), this is my snippet code in onSensorChanged method:

float azimut = orientation[0]; // orientation contains: azimut, pitch and roll
float azimutDegrees = (float) (azimut * 180 / Math.PI);
mapFragment.changeFovDirection(azimutDegrees);
Community
  • 1
  • 1
Miguel
  • 302
  • 3
  • 9