1

How do you show a device's location and orientation in a Google Maps (API 2) fragment on Android? The built-in Maps app shows the device's location and orientation with a small dot and an arrow; is it possible to do this in a Map fragment? Is the only option to read the sensors manually and draw polygons, or is there a built-in solution?

Phoebe
  • 2,774
  • 3
  • 22
  • 27
  • I can turn on the my-location layer to show the current GPS location, as well as, I guess, the GPS-calculated bearing. What I need to show is the the device's orientation according to it's magnetometer / accelerometer readings, like the Maps app does. – Phoebe Mar 20 '14 at 22:47

1 Answers1

0

It's not a built-in way to do this, but it works with the existing infrastructure.

The my-location layer can show the GPS-reported location and the GPS-reported bearing (based on movement) with an arrow indicator. This can be hacked using GoogleMap.setLocationSource with a custom LocationSource class. The basics are to make a new LocationSource, make it a LocationListener and a SensorEventListener, then have it produce a Location object that uses data from the location system for latitude, longitude, altitude, and accuracy, but use data from the magnetometer and accelerometer to calculate the compass direction and provide that data to Location.setBearing.

Phoebe
  • 2,774
  • 3
  • 22
  • 27