How to get a list of Android.Locations.GpsSatellite from Android.Locations.GpsStatus.Satellites?

LeszekChwalinskiLeszekChwalinski PLMember
edited April 2014 in Xamarin.Android

I need to do "foreach" through Android.Locations.GpsStatus.Satellites, however i couldnt get this iteration.I tried this:

    Android.Locations.LocationManager locMgr = activity.GetSystemService(Android.Content.Context.LocationService) as Android.Locations.LocationManager;
            Android.Locations.GpsStatus gpsStat = locMgr.GetGpsStatus(null);

    Android.Runtime.JavaList<GpsSatellite> jl = new JavaList<GpsSatellite>(gpsStat.Satellites.ToEnumerable<GpsSatellite>());
            List<GpsSatellite> ll = jl.ToList<GpsSatellite>();

            IEnumerable<System.Object> ie = gpsStat.Satellites.ToEnumerable<System.Object>();
            List<System.Object> ieList = jl.ToList<System.Object>();

            IEnumerable<Android.Locations.GpsSatellite> ie2 = gpsStat.Satellites.ToEnumerable<Android.Locations.GpsSatellite>();
            List<Android.Locations.GpsSatellite> ieList2 = ie2.ToList<Android.Locations.GpsSatellite>();

            IEnumerable<Java.Lang.Object> ie3 = gpsStat.Satellites.ToEnumerable<Java.Lang.Object>();
            List<Java.Lang.Object> ielist3 = ie3.ToList<Java.Lang.Object>();

In each case the list<> had 0 items. I know that GPS was focused and acquired about 11 satelites. So how it should look like?

Posts

  • AndreyZhylaAndreyZhyla UAMember
    public class LocationService : Java.Lang.Object, ILocationService, ILocationListener, GpsStatus.IListener, IJavaObject, IDisposable
        {
           ....
             _LocationManager.RequestLocationUpdates("gps", 0,40, this);
             _LocationManager.AddGpsStatusListener(this);
           .....
             public void OnGpsStatusChanged(GpsEvent e)
               {
                   int inView = 0;
                   int inFix = 0;
    
                   if (_LocationManager != null)
                   {
                       GpsStatus gpsStatus = _LocationManager.GetGpsStatus(null);
                       Java.Util.IIterator ie = gpsStatus.Satellites.Iterator();
    
                       while (ie.HasNext)
                       {
                           GpsSatellite s = (GpsSatellite)ie.Next();
                           inView = (1 + inView);
                           if (s.UsedInFix())
                           {
                               inFix = inFix + 1;
                           }
                       }
                   }
                }
    
Sign In or Register to comment.