public class GPS
extends java.lang.Object
new Thread() { public void run() { gps = new GPS(); for (int i = 0; i < 60*2 && gps.location[0] == 0; i++) // wait 60s { Vm.safeSleep(500); try { gps.retrieveGPSData(); } catch (GPSDisabledException gde) { Toast.show("Please enable GPS!",2000); } catch (Exception eee) { eee.printStackTrace(); break; } } } }.start();If the GPS fails connecting to the satellites, and the phone has signal, you can use the cell tower location as a rough location. The precision is vary between 50m to 3km, depending where the phone is. You can get the latitude and longitude using CellInfo.toCoordinates. See the tc.samples.maps.GoogleMaps sample.
GPS
,
CellInfo.toCoordinates()
Modifier and Type | Field and Description |
---|---|
double |
direction
Stores the direction in degrees from the North.
|
static int |
HIGH_GPS_PRECISION
Used in gpsPrecision
|
static double |
INVALID
A value that indicates that invalid data was retrieved.
|
Time |
lastFix
Stores the time of the last updated.
|
double[] |
location
Stores the location - latitude on first index (0) and longitude on second index (1).
|
static int |
LOW_GPS_PRECISION
Used in gpsPrecision
|
java.lang.String |
lowSignalReason
The reason for the low signal, if retrieveGPSData returned false.
|
java.lang.String |
messageReceived
The retrieved message, or null in Windows Mobile and Android.
|
double |
pdop
The last PDOP, if any.
|
int |
precision
Defines the GPS precision (currently has effect only on Android):
if HIGH, only the GPS is used, if LOW, then Google Play Services is also used.
|
int |
satellites
Number of satellites in view.
|
double |
velocity
Stores the speed in knots.
|
Constructor and Description |
---|
GPS()
Constructs a GPS control.
|
GPS(int precision)
Constructs a GPS control, with the given precision.
|
GPS(PortConnector sp)
Constructs a GPS control with the given serial port.
|
Modifier and Type | Method and Description |
---|---|
protected void |
finalize() |
double |
getLatitude()
Returns the latitude (
location[0] ). |
double |
getLongitude()
Returns the longitude (
location[1] ). |
static java.lang.String |
getWinCEGPSCom()
Returns the Windows CE GPS COM port, which can be used to open a PortConnector.
|
boolean |
retrieveGPSData()
Call this method to retrieve the data from the GPS.
|
void |
stop()
Closes the underlying PortConnector or native api.
|
static double |
toCoordinate(java.lang.String s,
char dir)
Returns the coordinate of the given string and direction.
|
static java.lang.String |
toCoordinateGGMMSS(java.lang.String coord,
char dir) |
public double[] location
INVALID
.public double direction
INVALID
.public double velocity
INVALID
.public int satellites
public Time lastFix
public java.lang.String messageReceived
public double pdop
INVALID
.public java.lang.String lowSignalReason
public static final int HIGH_GPS_PRECISION
public static final int LOW_GPS_PRECISION
public int precision
public static final double INVALID
public GPS() throws IOException
GPSDisabledException
- If GPS is disabledIOException
- If something goes wrong or if there's already an open instance of the GPS classpublic GPS(int precision) throws IOException
GPSDisabledException
- If GPS is disabledIOException
- If something goes wrong or if there's already an open instance of the GPS classpublic GPS(PortConnector sp) throws IOException
PortConnector sp = new PortConnector(PortConnector.BLUETOOTH, 9600); sp.setReadTimeout(500); gps = new GPS(sp);Don't use this constructor under Android nor Windows Mobile.
IOException
- If something goes wrong or if there's already an open instance of the GPS classGPS()
public static java.lang.String getWinCEGPSCom()
String com; if (Settings.isWindowsDevice() && (com = GPS.getWinCEGPSCom()) != null) sp = new PortConnector(Convert.chars2int(com), 9600, 7, PortConnector.PARITY_EVEN, 1);
public void stop()
public double getLatitude()
location[0]
).public double getLongitude()
location[1]
).public static double toCoordinate(java.lang.String s, char dir)
s
- the string in coordinate format.dir
- the direction: SWENpublic static java.lang.String toCoordinateGGMMSS(java.lang.String coord, char dir) throws InvalidNumberException
InvalidNumberException
public boolean retrieveGPSData()
lowSignalReason
protected void finalize()
finalize
in class java.lang.Object