Jump to content

Workout, a Tizen Sample App: Calculating Distance Traveled

Recommended Posts


This is the second blog in a series to introduce the sample application Workout, a Tizen example for monitoring health sensors on a wearable device.

The previous blog, Workout -- A Tizen Sample App for Monitoring Health Sensors, introduced the sample application, Workout, for runners who own a wearable device. In this blog, I will describe how one of the key features, traveled distance, is calculated.



To calculate the traveled distance, the application uses the LocationService class providing location-related GPS data. This service uses the Tizen.Location API to initialize the GPS receiver:


/// <summary>
/// Initializes LocationService class instance.
/// </summary>
private LocationService()
    _locator = new Locator(LocationType.Hybrid)
        Interval = _gpsCallbackInterval

The API is also used to set the change handlers:


/// <summary>
/// Sets service listeners.
/// </summary>
private void AttachEvents()
    _locator.ServiceStateChanged += (sender, args) => ServiceStateChanged?.Invoke(this, args.ServiceState);
    _locator.LocationChanged += (sender, args) => LocationChanged?.Invoke(this, args.Location);
    _locator.SettingChanged += (sender, args) => SettingChanged?.Invoke(this, args.IsEnabled);

Every time the location changes, the LocationChanged event is invoked with the new location.

This event has an attached listener in LocationModel which receives the new location object. The new location is used to calculate the distance to the previous location and stored in a _locationData object:


_locationData.Distance += location.GetDistanceTo(_lastLocation) / SettingsService.Instance.Distance.UnitToKmRatio;

The new location data is passed to MainModel, where all workout data are gathered and processed before being sent to viewModels.

The entire flow of location data and other workout data is described in detail at tizenschool.org

In the next blog in this series, I will discuss how data is gathered from the heart rate monitor.

View the full blog at its source

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Similar Topics

    • By Samsung Newsroom
      View the full blog at its source
    • By Alex
      cnet is covering Samsung's CES press conference, the South Korean electronics giant will show off its latest crop of TVs and home appliances during its presentation at the Consumer Electronics Show in Las Vegas.
      Samsung's presentation starts at 2 p.m. PT on Monday, and we'll be bringing you all the news and commentary from inside the Mandalay Bay hotel on the Las Vegas Strip. I'll be live blogging along with David Katzmaier, and James Martin will provide photography from the event.
      Samsung's 2015 CES press conference: Join us Monday (live blog)

  • Create New...