locked
"OnLocationChanged" method is never called when trying to create a geolocation listener? RRS feed

  • Question

  • User4279 posted

    I have used the same code in here http://docs.xamarin.com/recipes/android/osdeviceresources/gps/getcurrentdevice_location in order to get the current location of the user but it never calls the "OnLocationChanged" method. Is it a bug? I have seen it in here and here and here as well.

    Tuesday, April 2, 2013 2:05 PM

All replies

  • User1067 posted

    Same problem here. Native implementation works fine, Xamarin.Android implementation doesn't.

    Wednesday, March 12, 2014 6:43 PM
  • User35 posted

    Just tried the sample on my Nexus 5 (Android 4.4.2) and, well, it "works on my machine". I'd suggest checking the logcat output from the sample - there might be some clues in there as to why the callbacks aren't being invoked.

    Wednesday, March 12, 2014 7:19 PM
  • User35 posted

    Just to prove something, can you change line 79 in Activity1.cs from

    _locationProvider = String.Empty;
    

    to

    throw new Exception("Unable to find a location provider for the specified criteria.");
    
    Thursday, March 13, 2014 2:02 AM
  • User1067 posted

    Hi Tom, thanks for responding.

    Well, a Nexus 5 (4.4.2) is my main test device and it doesn't work. :( Buy hey, let's hope it's just a small thing I've overseen. :)

    So, here are my other boundary conditions:

    1. Set Location mode to High accuracy in device settings

    2. Target API is 18, minimum 10, compile API 18

    3. Permissions (also set in project settings): [assembly: UsesPermission(Android.Manifest.Permission.Internet)] [assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)] [assembly: UsesPermission(Manifest.Permission.AccessFineLocation)]

    4. German language settings ...

    I've attached my quick'n'dirty test code from yesterday 9 pm (UTC+1 here :))

    Please notice: GPS accuracy is set to Accuracy.Fine. It works when, when set to coarse and throws an exception when set to something else (but let's concentrate on fine).

    Thursday, March 13, 2014 7:13 AM
  • User1067 posted

    Well, in some kind of magic way it just works now. It's somehow slower than the native implementation (atleast on the N5, N4 is super fast), but it works. :[ Thanks for your effort.

    Thursday, March 13, 2014 7:54 AM
  • User35 posted

    I don't think that the delay you're seeing is an issue with Xamarin.Android. I find that the GPS on the Android devices I've used (ADP1/Nexus 1/Galaxy Nexus/Xoom/Nexus 4/Nexus 5) can really vary with how long it takes to get a fix. Sometimes it's almost instantaneous, sometimes it's a wait.

    Thursday, March 13, 2014 1:35 PM
  • User1067 posted

    Yeah, but it's kind of weird that an native implementation with the exact same options gets faster results on the same device at the same location. Every request with Xamarin in the middle takes up to 5 minutes, whereas native is done in under 10 seconds. It's okay when the first gps fix takes a moment, but not every new request.

    Feel free to check it yourself.

    Thursday, March 13, 2014 3:26 PM