/*
* 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 double latitude = -999.0;
public double longitude = -999.0;
public LocationProvider provider = null;
public Location location = null;
public int lastupdate = 0;
public GPS()
{
}
public void startLocationUpdate()
{
try
{
provider = LocationProvider.getInstance(null);
if(provider != null)
provider.setLocationListener(new GPSListener(), 1, -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);
synchronized(net.rim.device.api.ui.UiApplication.getEventLock())
{
ociApp.theScreen.latlon.setText(""+latitude+", "+longitude);
}
}
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();
}
}
}
}