Skip to content

Commit cc6b911

Browse files
committed
Set IsListening. Previously always returned false
1 parent 4c940fe commit cc6b911

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

nuget/Plugin.nuspec

-8
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,6 @@
107107
<file src="src\Geolocator.Plugin.Abstractions\bin\Release\Plugin.Geolocator.Abstractions.dll" target="lib\Xamarin.iOS10\Plugin.Geolocator.Abstractions.dll" />
108108
<file src="src\Geolocator.Plugin.Abstractions\bin\Release\Plugin.Geolocator.Abstractions.xml" target="lib\Xamarin.iOS10\Plugin.Geolocator.Abstractions.xml" />
109109

110-
<!--UWP-->
111-
<file src="src\Geolocator.Plugin.UWP\bin\Release\Plugin.Geolocator.dll" target="lib\UAP10\Plugin.Geolocator.dll" />
112-
<file src="src\Geolocator.Plugin.UWP\bin\Release\Plugin.Geolocator.xml" target="lib\UAP10\Plugin.Geolocator.xml" />
113-
<file src="src\Geolocator.Plugin.UWP\bin\Release\Plugin.Geolocator.pdb" target="lib\UAP10\Plugin.Geolocator.pdb" />
114-
<file src="src\Geolocator.Plugin.Abstractions\bin\Release\Plugin.Geolocator.Abstractions.dll" target="lib\UAP10\Plugin.Geolocator.Abstractions.dll" />
115-
<file src="src\Geolocator.Plugin.Abstractions\bin\Release\Plugin.Geolocator.Abstractions.xml" target="lib\UAP10\Plugin.Geolocator.Abstractions.xml" />
116-
<file src="src\Geolocator.Plugin.Abstractions\bin\Release\Plugin.Geolocator.Abstractions.pdb" target="lib\UAP10\Plugin.Geolocator.Abstractions.pdb" />
117-
118110
<!--net45-->
119111
<file src="src\Geolocator.Plugin.Net45\bin\Release\Plugin.Geolocator.dll" target="lib\net45\Plugin.Geolocator.dll" />
120112
<file src="src\Geolocator.Plugin.Net45\bin\Release\Plugin.Geolocator.xml" target="lib\net45\Plugin.Geolocator.xml" />

src/Geolocator.Plugin.Android/GeolocatorImplementation.cs

+3-5
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public GeolocatorImplementation()
5353
/// <inheritdoc/>
5454
public bool IsListening
5555
{
56-
get { return listener != null; }
56+
get { return gpsManager.IsListening; }
5757
}
5858
/// <inheritdoc/>
5959
public double DesiredAccuracy
@@ -144,8 +144,8 @@ public async Task<bool> StartListeningAsync(int minTime, double minDistance, boo
144144
if (IsListening)
145145
throw new InvalidOperationException("This Geolocator is already listening");
146146

147-
gpsManager.OnStart();
148147
gpsManager.PositionChanged += OnListenerPositionChanged;
148+
gpsManager.OnStart();
149149

150150
return true;
151151
}
@@ -163,9 +163,7 @@ public Task<bool> StopListeningAsync()
163163
private readonly LocationManager manager;
164164
private readonly GoogleConnectionHandler gpsManager; // Google Play Services location manager
165165
private string headingProvider;
166-
167-
private GeolocationContinuousListener listener;
168-
166+
169167
private readonly object positionSync = new object();
170168
private Position lastPosition;
171169
/// <inheritdoc/>

src/Geolocator.Plugin.Android/GoogleConnectionHandler.cs

+14-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class GoogleConnectionHandler : Java.Lang.Object, GoogleApiClient.IConnectionCal
2121
{
2222
public int REQUEST_CHECK_SETTINGS = 11000;
2323

24+
public bool IsListening { get; private set; }
25+
2426
public GoogleApiClient GoogleApiClient
2527
{
2628
get;
@@ -35,8 +37,7 @@ public LocationRequest LocationRequest
3537

3638
public GoogleConnectionHandler()
3739
{
38-
39-
40+
IsListening = false;
4041
// Create an instance of GoogleAPIClient.
4142
GoogleApiClient = new GoogleApiClient.Builder(Application.Context)
4243
.AddConnectionCallbacks(this)
@@ -69,7 +70,16 @@ public Position GetPosition()
6970

7071
public void OnStart()
7172
{
72-
GoogleApiClient.Connect();
73+
if (GoogleApiClient.IsConnected)
74+
{
75+
LocationServices.FusedLocationApi.RequestLocationUpdates(
76+
GoogleApiClient, LocationRequest, this);
77+
IsListening = true;
78+
}
79+
else
80+
{
81+
GoogleApiClient.Connect();
82+
}
7383
}
7484

7585
public void OnStop()
@@ -80,10 +90,9 @@ public void OnStop()
8090
/// <inheritdoc/>
8191
public void OnConnected(Bundle connectionHint)
8292
{
83-
8493
LocationServices.FusedLocationApi.RequestLocationUpdates(
8594
GoogleApiClient, LocationRequest, this);
86-
95+
IsListening = true;
8796
}
8897

8998
/// <inheritdoc/>

0 commit comments

Comments
 (0)