Hacky fix for GeoLocation on the 2.1 Emulator

This commit is contained in:
Brock Whitten 2010-01-29 16:02:20 -08:00
parent cf70f7d4a7
commit e01dfec400

View File

@ -2,6 +2,7 @@ package com.phonegap;
import android.content.Context; import android.content.Context;
import android.location.Location; import android.location.Location;
import android.location.LocationManager;
import android.webkit.WebView; import android.webkit.WebView;
public class GeoListener { public class GeoListener {
@ -10,6 +11,7 @@ public class GeoListener {
String failCallback; String failCallback;
GpsListener mGps; GpsListener mGps;
NetworkListener mNetwork; NetworkListener mNetwork;
LocationManager mLocMan;
Context mCtx; Context mCtx;
private WebView mAppView; private WebView mAppView;
@ -20,8 +22,14 @@ public class GeoListener {
id = i; id = i;
interval = time; interval = time;
mCtx = ctx; mCtx = ctx;
mGps = new GpsListener(mCtx, interval, this); mGps = null;
mNetwork = new NetworkListener(mCtx, interval, this); mNetwork = null;
mLocMan = (LocationManager) mCtx.getSystemService(Context.LOCATION_SERVICE);
if (mLocMan.getProvider(LocationManager.GPS_PROVIDER) != null)
mGps = new GpsListener(mCtx, interval, this);
if (mLocMan.getProvider(LocationManager.NETWORK_PROVIDER) != null)
mNetwork = new NetworkListener(mCtx, interval, this);
mAppView = appView; mAppView = appView;
} }
@ -63,9 +71,13 @@ public class GeoListener {
} }
public Location getCurrentLocation() { public Location getCurrentLocation() {
Location loc = mGps.getLocation(); Location loc = null;
if (loc == null) if (mGps != null)
loc = mGps.getLocation();
if (loc == null && mNetwork != null)
loc = mNetwork.getLocation(); loc = mNetwork.getLocation();
else
loc = new Location(LocationManager.NETWORK_PROVIDER);
return loc; return loc;
} }
} }