See
Obtaining
User Location.
If it doesn’t work, try
LocationManager.NETWORK_PROVIDER
instead of
LocationManager.GPS_PROVIDER
.
The GPS is expensive, so turn it off when not in use.
For
onPause
and
onResume
,
see the
flowchart.
We used them to turn the accelerometer on and off in
Pearl.
MainActivity.java
activity_main.xml
AndroidManifest.xml
has
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
.
The location of the Woolworth Building is
Latitude: 40.712222° North = 40° 42′ 44″ North
Longitude: 74.008056° West = –74° 0′ 29″ West
Remember that longitude west of the Prime Meridian is negative.
Click on the GPS icon in the right margin of the Genymotion emulator. It contains the initials GPS. Or launch the Genymotion Shell in the Applications folder.
Genymotion Shell > help Genymotion Shell > help gps Genymotion Shell > gps getstatus GPS status: enabled Genymotion Shell > gps getaccuracy GPS Accuracy: 0 GPS status: enabled Genymotion Shell > gps setlatitude 40.712222 Genymotion Shell > gps setlongitude -74.008056 Genymotion Shell > gps getlatitude Genymotion Shell > gps getlongitude