Bug 12719 - Position.Speed returns 0
Summary: Position.Speed returns 0
Alias: None
Product: Mobile API (Preview)
Classification: Xamarin
Component: Xamarin.Android ()
Version: Preview 0.6.3
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bill Holmes
Depends on:
Reported: 2013-06-17 07:59 UTC by Paul Johnson
Modified: 2017-05-24 20:59 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Paul Johnson 2013-06-17 07:59:26 UTC
When checking for the speed of movement, Speed always records 0.

Consider this code (it is a modified version of the code supplied with xamarin.mobile)

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)
     string s = string.Format("Speed = {0}, Long = {1}, Lat = {2}", sod, lng, lat);
     RunOnUiThread(() => Toast.MakeText(context, s, ToastLength.Short).Show());

When the location changes, the Toast should show a change in speed, lat and long. While lat and long alter, speed remains constant at 0. I can be in my car at 70mph and speed is still 0.

I've not tested this on iOS and if there is a difference, I'll add a comment to this bug.
Comment 2 Eric Maupin 2013-06-17 09:42:17 UTC
It shouldn't always be 0, so I will look into that, but in general you should not hope to use .Speed for display a speed to the user (see remarks http://componentsapi.xamarin.com/?link=P%3aXamarin.Geolocation.Position.Speed). If you want to display a speed that is usable to users, you'll need to calculate it yourself.
Comment 3 Paul Johnson 2013-06-17 09:48:04 UTC

As for the calculation of speed, if this is latching onto the standard ILocationService listener for position changed, then speed really should be varying that much from the standard Android speed listener code. Looks like I'll need to find a quick way to calculate distance based on GPS :)
Comment 4 Paul Johnson 2013-07-11 10:05:30 UTC
Has there been any movement on this bug?
Comment 5 Matthew Leibowitz 2017-05-24 20:55:55 UTC
This appears to be fixed in a later version (v0.7.7 works for me).

I would also like to point out that the Mobile API is being deprecated in favor of various plugins (which have the equivalent/same API):
 - Contacts: https://www.nuget.org/packages/Xam.Plugin.Contacts
 - Geolocator: https://www.nuget.org/packages/Xam.Plugin.Geolocator
 - Media: https://www.nuget.org/packages/Xam.Plugin.Media

This plugin model has several advantages:
 - Each plugin is independent, and can be updated as such
 - It is no longer an all-or-nothing package
 - Plugins can be mixed/replaced with other plugins that offer similar features

Thanks for using the Mobile API, and we hope that the new plugin model will enable you to produce even better mobile apps.
Comment 6 Matthew Leibowitz 2017-05-24 20:59:48 UTC
I also just want to point out that the speed is set in the same way as the latitude and longitude:

    if (nativeLocation.HasSpeed) {
        position.Speed = nativeLocation.Speed;

It may be the case that particular devices do not actually have speed data.