1

I have followed this answer to implement a custom compass. But obviously it points to the Magnetic North Pole (I suppose).

I spent some hours trying doing the math, but I'm not a topographer and I gave up.

I found some partial guide in which they, instead using an imageView, they draw some kind of line, but I could not understand how to re-implement in my case.

For example, the first 2 answers of this post seemed to me enough reliable ì, but when I tried to integrate them into my code, I wasn't able to get them working. So I asked to the authors to post more code, but the first one said that probably is an outdated way to get location with current Android's API, the second one said that was no more on the project.

Are you aware of which is the current best way to fetch my location and update it?

Thanks in advance

Community
  • 1
  • 1
M4rk
  • 2,172
  • 5
  • 36
  • 70

1 Answers1

0

Check out https://developer.android.com/guide/topics/sensors/sensors_position.html Using the Game Rotation Vector Sensor. This is a way to use a new "north" that isn't the magnetic north.

To get the current location place either of the following in your manifest file:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
or
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

Without the permissions, the app with crash at run time.

Then, you should be able to follow this tutorial that google offers: http://developer.android.com/training/location/retrieve-current.html#CheckServices

The quick solution is something like:

public class MainActivity extends FragmentActivity implements
    GooglePlayServicesClient.ConnectionCallbacks,
    GooglePlayServicesClient.OnConnectionFailedListener {
    ...
    // Global variable to hold the current location
    Location mCurrentLocation;
    ...
    mCurrentLocation = mLocationClient.getLastLocation();
    ...
}