[go: up one dir, main page]

Menu

[r11]: / GPS.java  Maximize  Restore  History

Download this file

79 lines (70 with data), 2.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* GPS.java
*
* Copyright (C) 2008 by delta_foxtrot@users.sourceforge.net
* http://gpsavenger.sf.net
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
import javax.microedition.location.*;
class GPS
{
public LocationProvider provider = null;
public Location location = null;
public double latitude = -999.0;
public double longitude = -999.0;
public int lastupdate = 0;
public GPS()
{
}
public void startLocationUpdate()
{
try
{
provider = LocationProvider.getInstance(null);
if(provider != null)
provider.setLocationListener(new GPSListener(), 10, -1, -1);
} catch (Exception e) {}
}
public void stopLocationUpdate()
{
provider.setLocationListener(null, -1, 0, 0);
provider.reset();
provider = null;
}
private void newLocation(LocationProvider prov, Location loc)
{
provider = prov;
location = loc;
QualifiedCoordinates qc = location.getQualifiedCoordinates();
latitude = qc.getLatitude();
longitude = qc.getLongitude();
lastupdate = (int)(System.currentTimeMillis() / 1000);
}
private class GPSListener implements LocationListener
{
public void locationUpdated(LocationProvider provider, Location location)
{
newLocation(provider, location);
}
public void providerStateChanged(LocationProvider provider, int newState)
{
if (newState == provider.OUT_OF_SERVICE)
{
startLocationUpdate();
}
}
}
}