Xamarin distance between 2 location in km ?

cristopheB 551 Reputation points
2023-01-17T13:18:20.6266667+00:00

Hello,

I would like to know, how to have the distance in km between two location (lat / long)

For to do that, i used the method distance to and after I divide by 1000 ..

But, if i take two location on google maps , obtain lat long and try with this method to obtain the distance ,,There is difference ..

The method distanceTo give me for example 15km as result between my two locations.

If i go to google direction and do the same, i have more km ..

Why ?

My goal, is to present to the end user several locations next to him.

And to give the choice to the end user to select the best place.

How to have a good result ?

thanks for you suggestion

            float distance = locationA.DistanceTo(locationB);
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,292 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 68,261 Reputation points Microsoft Vendor
    2023-01-18T03:32:18.66+00:00

    Hello,

    From Xamarin Distance between Two Locations document,

    This calculated distance does not take roads or other pathways into account, and is merely the shortest distance between the two points along the surface of the Earth, also known as the great-circle distance or colloquially, the distance "as the crow flies."

    However, Google map calculated distance with roads or other pathways. You will more miles.

    My goal, is to present to the end user several locations next to him.

    You can use Xamarin distance API but add a note about the result of the calculation.

    If you have router's function, you can integrate google map API to calculate it.

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful