From e01dfec4001c4681f556d8d5ea62492905a49804 Mon Sep 17 00:00:00 2001 From: Brock Whitten Date: Fri, 29 Jan 2010 16:02:20 -0800 Subject: [PATCH] Hacky fix for GeoLocation on the 2.1 Emulator --- framework/src/com/phonegap/GeoListener.java | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/framework/src/com/phonegap/GeoListener.java b/framework/src/com/phonegap/GeoListener.java index 98dc3001..45267b6b 100644 --- a/framework/src/com/phonegap/GeoListener.java +++ b/framework/src/com/phonegap/GeoListener.java @@ -2,6 +2,7 @@ package com.phonegap; import android.content.Context; import android.location.Location; +import android.location.LocationManager; import android.webkit.WebView; public class GeoListener { @@ -10,6 +11,7 @@ public class GeoListener { String failCallback; GpsListener mGps; NetworkListener mNetwork; + LocationManager mLocMan; Context mCtx; private WebView mAppView; @@ -20,8 +22,14 @@ public class GeoListener { id = i; interval = time; mCtx = ctx; - mGps = new GpsListener(mCtx, interval, this); - mNetwork = new NetworkListener(mCtx, interval, this); + mGps = null; + 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; } @@ -63,9 +71,13 @@ public class GeoListener { } public Location getCurrentLocation() { - Location loc = mGps.getLocation(); - if (loc == null) + Location loc = null; + if (mGps != null) + loc = mGps.getLocation(); + if (loc == null && mNetwork != null) loc = mNetwork.getLocation(); + else + loc = new Location(LocationManager.NETWORK_PROVIDER); return loc; } }