Here is the code which finally I have to settle down with
1)Create a class , say
DistanceModel.cs
public class DistanceModel
{
public int PlaceId { get; set; }
public string Name { get; set; }
public double Latitute { get; set; }
public double Longitude { get; set; }
}
2)Then include the below code in whichever file you want to , say
MainPage.cs
/*Call GetAllNearestFamousPlaces() method to get list of nearby places depending
upon user current location.
Note: GetAllNearestFamousPlaces() method takes 2 parameters as input
that is GetAllNearestFamousPlaces(user_current_Latitude,user_current_Longitude) */
public void GetAllNearestFamousPlaces(double currentLatitude,double currentLongitude)
{
List<DistanceModel> Caldistance = new List<DistanceModel>();
var query = (from c in sdbml.Places
select c).ToList();
foreach (var place in query)
{
double distance = Distance(currentLatitude, currentLongitude, place.Latitude, place.Logitude);
if (distance < 25) //nearbyplaces which are within 25 kms
{
DistanceModel dist = new DistanceModel();
dist.Name = place.PlaceName;
dist.Latitute = place.Latitude;
dist.Longitude = place.Logitude;
dist.PlaceId = place.PlaceId;
Caldistance.Add(getDiff);
}
}
}
private double Distance(double lat1, double lon1, double lat2, double lon2)
{
double theta = lon1 - lon2;
double dist = Math.Sin(deg2rad(lat1)) * Math.Sin(deg2rad(lat2)) + Math.Cos(deg2rad(lat1)) * Math.Cos(deg2rad(lat2)) * Math.Cos(deg2rad(theta));
dist = Math.Acos(dist);
dist = rad2deg(dist);
dist = (dist * 60 * 1.1515) / 0.6213711922; //miles to kms
return (dist);
}
private double deg2rad(double deg)
{
return (deg * Math.PI / 180.0);
}
private double rad2deg(double rad)
{
return (rad * 180.0 / Math.PI);
}
It worked for me, Hope it will help you to .