Forum Xamarin Cross Platform with Xamarin

Using geolocation for speed on Android

nodoidnodoid GBMember, Beta ✭✭✭


Not sure if this is a bug in my code or Xam.Mobile for getting the speed.

I'm using a modified version of the sample code supplied to check the speed I'm travelling at. The code updates the geolocation address fine, but not the speed, that remains at zero (despite being in the car at 30mph).

The code I'm using looks like this

private void OnPositionChanged(object sender, PositionEventArgs e)
    LocationChanged(e.Position.Longitude, e.Position.Latitude, e.Position.Speed);

private void LocationChanged(double lng, double lat, double spd)
     geoLoc.GetAddress(lng, lat);

            string s = string.Format("Speed = {0}", spd);
            RunOnUiThread(()=>Toast.MakeText(context, s, ToastLength.Short).Show());

     double speed = spd;
     double kmh = speed * 3.6f;
     double mph = speed * 2.2369362920544f;

                speedms.Text = speed.ToString("N2");
                speedkmh.Text = kmh.ToString("N2");
                speedmph.Text = mph.ToString("N2");
                string loc = string.Empty;
                if (myUtilClass.GeoLocationAddress.Count != 0)
                    foreach (string t in myUtilClass.GeoLocationAddress)
                        loc += t + ", ";
                    loc.Remove(loc.LastIndexOf(", "));
                    loc = "No idea whatsoever";
                currentLoc.Text = loc;

Should the speed be zero at all times or am I using the wrong object for speed?



  • haronrpharonrp Member

    I am having the same problem both on my iOS and android device. Is this problem solved? need a little help here. :smile:

Sign In or Register to comment.