Forum Xamarin Xamarin.Android

Making a List with Locations and finding out if any of them are near my current Location

ChristopherDrososChristopherDrosos GRMember ✭✭
edited September 2015 in Xamarin.Android

I would like to make an App that will have some locations and i would like to know if i am near any of them and to display for example how far away i am using any provider available preferably WiFi or Cellural data (i dont care much about accuracy).
How i can do that on Xamarin.Android?
For finding out my location i believe this article https://developer.xamarin.com/guides/android/platform_features/maps_and_location/location/ will be good enough but how i can compare a location with other locations and find out the difference in meters between them?

Best Answer

Answers

  • oh that simple? :D nice, will try it and post back, thanks

  • GauravKatdareGauravKatdare USMember ✭✭

    Hi,
    This is the solution which worked for me.
    I used Xamaarin.Essentials library.

    var DelhiLocation = new Location(28.636935, 77.217496);
    foreach(var item in locationData.Locations)
    {
        item.DistanceBetween = Location.CalculateDistance(DelhiLocation, new Location(item.Latitude,item.Longitude), DistanceUnits.Kilometers);
    }
    System.Collections.Generic.List<LocationModel> nearest = locationData.Locations.OrderBy(x => x.DistanceBetween).ToList();
    

    This will return all the locations with Orderby learest to the source location.

Sign In or Register to comment.