Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7856507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:44:04+00:00 2026-06-02T20:44:04+00:00

I am using the MvvmCross framework to build a cross platform (iOS, Android, WP7)

  • 0

I am using the MvvmCross framework to build a cross platform (iOS, Android, WP7) application. I am using the MvxGeoLocationWatcher which creates MvxGeoLocation objects for me with the required Long, Lat, speed, heading etc.

I need to find the distance between two locations (as the crow flies). On Android I call fromLocation.distanceTo(toLocation). On iOs I would use CLLocationDistance distance = [fromLocation distanceFromLocation:toLocation];.

So both these platforms use a method on the location to calculate the distance and this isn’t currently available on the MvxGeoLocation object.

Are there plans to add it soon? If not what would be the best approach for me to add this functionality?

  1. Would I change the class itself and provide platform specific implementations – perhaps by making it a partial class and putting the specific code in a platform specific code partial class. Or perhaps by using extension methods?
  2. Or perhaps its best done as method that takes two points and returns the distance. In which case should this method be on MvxGeoLocationWatcher?
  3. Add the calculation algorithm in myself perhaps using something from Calculate distance of two geo points in km c# and forget about using the platform specific implementations
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T20:44:05+00:00Added an answer on June 2, 2026 at 8:44 pm

    Currently mvvmcross has deliberately not included lat/lng calculations.

    The motivation for this was:

    • to keep the code size down – not every app needs those calculations
    • further I have in my mind that some calculations are better done by native libraries rather than generic C# – e.g. some polygon calculations would benefit from native hardware acceleration. This type of thought is there not only for geo-calcuations, but also for other areas – e.g. whereever things like image manipulation are required, then using native acceleration makes sense.

    It may be that mvvmcross provides an “official” location helper IoC plugin (or set of extension methods) at some point in the future… e.g. it maybe that we build an IoC plugin around http://xamarin.com/mobileapi … and I’m also very happy for others to build and publish them too.

    So….

    At a very simple level, working out the distance between two lat/lng points is easy to do in C# – there are heaps of fairly simple code example available like the excellent javascript ones at http://www.movable-type.co.uk/scripts/latlong.html – and there are heaps of libraries on github and codeplex like http://sharpmap.codeplex.com/

    In RunSat (including on iPhone) I use:

    using System;
    
    namespace Cirrious.NewRunSat.Core.Models.Utils
    {
        public class DistanceCalcs
        {
            /// <summary>
            /// Calculates the distance between two points of latitude and longitude.
            /// Great Link - http://www.movable-type.co.uk/scripts/latlong.html
            /// </summary>
            /// <param name="lat1">First coordinate.</param>
            /// <param name="long1">First coordinate.</param>
            /// <param name="lat2">Second coordinate.</param>
            /// <param name="long2">Second coordinate.</param>
            /// <returns>the distance in metres</returns>
            public static Double DistanceInMetres(double lat1, double lon1, double lat2, double lon2)
            {
    
                if (lat1 == lat2 && lon1 == lon2)
                    return 0.0;
    
                var theta = lon1 - lon2;
    
                var distance = Math.Sin(deg2rad(lat1)) * Math.Sin(deg2rad(lat2)) +
                               Math.Cos(deg2rad(lat1)) * Math.Cos(deg2rad(lat2)) *
                               Math.Cos(deg2rad(theta));
    
                distance = Math.Acos(distance);
                if (double.IsNaN(distance))
                    return 0.0;
    
                distance = rad2deg(distance);
                distance = distance * 60.0 * 1.1515 * 1609.344;
    
                return (distance);
            }
    
            private static double deg2rad(double deg) {
              return (deg * Math.PI / 180.0);
            }
    
            private static double rad2deg(double rad) {
              return (rad / Math.PI * 180.0);
            }
        }
    }
    

    Note that the license on this snippet is CC attribution – because its derived from movable type – http://www.movable-type.co.uk/scripts/latlong.html:

    I offer these formulæ & scripts for free use and adaptation as my
    contribution to the open-source info-sphere from which I have received
    so much. You are welcome to re-use these scripts [under a simple
    attribution license, without any warranty express or implied] provided
    solely that you retain my copyright notice and a reference to this
    page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're developing a cross platform application for iOS, Android and WP7 by using MVVMCross
I am using the MvvmCross framework for cross device development. When I test my
I've created an app using MVVMCross, the IOS and Android versions are working but
Using android 2.3.3, I have a background Service which has a socket connection. There's
Using Android TelephonyManager an application can obtain the state of data activity over the
Using MVC2 I have an AJAX form which is posting to a bound model.
Using Delphi 2010. I am looking for (possibly) a function or procedure which can
For the past couple of weeks I've been working on developing a cross platform
using the arcsynthesis opengl tutorial and I'm trying to build the unofficial sdk that
Using Entity Framework CodeFirst, how do I create a created datetime column that gets

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.