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

I have used the same code in here http://docs.xamarin.com/recipes/android/os_device_resources/gps/get_current_device_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.

Posts

  • infoMantisinfoMantis DEUniversity ✭✭
    edited March 2014

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

  • TomOpgenorthTomOpgenorth CAXamarin Team Xamurai

    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.

  • TomOpgenorthTomOpgenorth CAXamarin Team Xamurai

    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.");
    
  • infoMantisinfoMantis DEUniversity ✭✭
    edited March 2014

    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).

  • infoMantisinfoMantis DEUniversity ✭✭
    edited March 2014

    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.

  • TomOpgenorthTomOpgenorth CAXamarin Team Xamurai

    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.

  • infoMantisinfoMantis DEUniversity ✭✭

    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.

Sign In or Register to comment.