Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi
i have succeeded in getting and saving latitude and longitude of a location into my database. i am also able to show this location on google map in my webpage. Now what i need is, i need to get latitude and longitude from database of a location (store) and find nearby locations (stores) of this location. these locations are saved in my database. Please help me out in searching nearby locations that are in my database.

Thanks
Posted

1 solution

this is the formula of the distance of two points: √(((x_2-x_1 )^2+(y_2-y_1 )^2))
write it in C#!
then make a table whit 3 column , first point, second point and distance!
and limit it with your need for example only 15 km!
then calculate your points distance whit others, for example in a for loop only the distance that under a number!
then use this query to bring other point!
C#
var points = (from point in context.distance where distance.fpoint_id == xy select point).ToList();

I think I give you the key!:)
 
Share this answer
 
Comments
S.Aijaz 9-Jun-12 0:36am    
Thanks for the quick reply and bringing a very valuable suggestion to the table. do you have a reference link or code example.
taha bahraminezhad Jooneghani 9-Jun-12 3:09am    
as you know this is my Idea so there is no reference and I never have this situation before this so i don't have an axample code.
maybe you can find a good model for your database here:
http://www.databaseanswers.org/data_models/
S.Aijaz 9-Jun-12 5:21am    
you are right i found some thing similar, but the problem is it does not give accurate distance in some cases. the function is :


public class CDistanceBetweenLocations
{
public static double Calc(double Lat1,
double Long1, double Lat2, double Long2)
{
/*
The Haversine formula according to Dr. Math.
http://mathforum.org/library/drmath/view/51879.html

dlon = lon2 - lon1
dlat = lat2 - lat1
a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2
c = 2 * atan2(sqrt(a), sqrt(1-a))
d = R * c

Where
* dlon is the change in longitude
* dlat is the change in latitude
* c is the great circle distance in Radians.
* R is the radius of a spherical Earth.
* The locations of the two points in
spherical coordinates (longitude and
latitude) are lon1,lat1 and lon2, lat2.
*/
double dDistance = Double.MinValue;
double dLat1InRad = Lat1 * (Math.PI / 180.0);
double dLong1InRad = Long1 * (Math.PI / 180.0);
double dLat2InRad = Lat2 * (Math.PI / 180.0);
double dLong2InRad = Long2 * (Math.PI / 180.0);

double dLongitude = dLong2InRad - dLong1InRad;
double dLatitude = dLat2InRad - dLat1InRad;

// Intermediate result a.
double a = Math.Pow(Math.Sin(dLatitude / 2.0), 2.0) +
Math.Cos(dLat1InRad) * Math.Cos(dLat2InRad) *
Math.Pow(Math.Sin(dLongitude / 2.0), 2.0);

// Intermediate result c (great circle distance in Radians).
double c = 2.0 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1.0 - a));

// Distance.
// const Double kEarthRadiusMiles = 3956.0;
const Double kEarthRadiusKms = 6376.5;
dDistance = kEarthRadiusKms * c;

return dDistance;
}

public static double Calc(string NS1, double Lat1, double Lat1Min,
string EW1, double Long1, double Long1Min, string NS2,
double Lat2, double Lat2Min, string EW2,
double Long2, double Long2Min)
{
double NS1Sign = NS1.ToUpper() == "N" ? 1.0 : -1.0;
double EW1Sign = NS1.ToUpper() == "E" ? 1.0 : -1.0;
double NS2Sign = NS2.ToUpper() == "N" ? 1.0 : -1.0;
double EW2Sign = EW2.ToUpper() == "E" ? 1.0 : -1.0;
return (Calc(
(Lat1 + (Lat1Min / 60)) * NS1Sign,
(Long1 + (Long1Min / 60)) * EW1Sign,
(Lat2 + (Lat2Min / 60)) * NS2Sign,
(Long2 + (Long2Min / 60)) * EW2Sign
));
}
}
taha bahraminezhad Jooneghani 9-Jun-12 10:51am    
share this as a question again!
maybe now more people can help you!
I just 21 years old with a good mind not a good expert!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900