Fixing Geolocation so it grabs data from the network faster

This commit is contained in:
Joe Bowser 2009-12-15 15:16:35 -08:00
parent 3898130a30
commit 9276729be5
3 changed files with 8 additions and 4 deletions

View File

@ -15,6 +15,7 @@ public class GeoBroker {
private WebView mAppView; private WebView mAppView;
private Context mCtx; private Context mCtx;
private HashMap<String, GeoListener> geoListeners; private HashMap<String, GeoListener> geoListeners;
private GeoListener listener;
public GeoBroker(WebView view, Context ctx) public GeoBroker(WebView view, Context ctx)
{ {
@ -23,8 +24,9 @@ public class GeoBroker {
} }
public void getCurrentLocation() public void getCurrentLocation()
{ {
GeoListener listener = new GeoListener("global", mCtx, 10000, mAppView); if (listener == null)
listener = new GeoListener("global", mCtx, 10000, mAppView);
} }
public String start(int freq, String key) public String start(int freq, String key)

View File

@ -35,6 +35,7 @@ public class GpsListener implements LocationListener {
private LocationManager mLocMan; private LocationManager mLocMan;
private static final String LOG_TAG = "PhoneGap"; private static final String LOG_TAG = "PhoneGap";
private GeoListener owner; private GeoListener owner;
private boolean hasData = false;
public GpsListener(Context ctx, int interval, GeoListener m) public GpsListener(Context ctx, int interval, GeoListener m)
{ {
@ -48,6 +49,7 @@ public class GpsListener implements LocationListener {
public Location getLocation() public Location getLocation()
{ {
cLoc = mLocMan.getLastKnownLocation(LocationManager.GPS_PROVIDER); cLoc = mLocMan.getLastKnownLocation(LocationManager.GPS_PROVIDER);
hasData = true;
return cLoc; return cLoc;
} }
@ -88,7 +90,7 @@ public class GpsListener implements LocationListener {
} }
public boolean hasLocation() { public boolean hasLocation() {
return (cLoc != null); return hasData;
} }
public void stop() public void stop()

View File

@ -47,7 +47,7 @@ public class NetworkListener implements LocationListener {
public Location getLocation() public Location getLocation()
{ {
cLoc = mLocMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); cLoc = mLocMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
return cLoc; return cLoc;
} }