this question has answer here:
first of all, i'm not sure if best way it, but...
i have amassed table of longitude , lattitude points zip codes in us. want able allow user choose zip code, select radius in miles (5, 10, 20, 40, etc...) , app list users in radius.
it doesn't need incredibly accurate, it's got close. i've been poking around looking other ways i'm stumped, , can't find example of using long/lat it.
if in c# work best. i'm not proficient @ java might able muddle through if absolutely necessary.
edit:
my coordinates this:
countrycode zipcode place statecode latitude longitude 95219 stockton ca 38.01 -121.3698 95220 acampo ca 38.2004 -121.2186 95227 clements ca 38.1929 -121.0811 95230 farmington ca 37.9945 -120.7926 95231 french camp ca 37.878 -121.2827 95234 holt ca 37.9344 -121.4261 95236 linden ca 38.032 -121.0493 this question not duplicate, linked question phone.
following code generates distance between instance of wgs84point , another. distance given assuming spherical earth , not take account earth's irregular shape.
public class wgs84point { const double maxdegreeslongitude = 180; const double mindegreeslongitude = -180; const double maxdegreeslatitude = 90; const double mindegreeslatitude = -90; readonly double _longitude; readonly double _latitude; public double latitude { { return _latitude; } } public double longitude { { return _longitude; } } public wgs84point(double longitude, double latitude) { if (longitude > maxdegreeslongitude || longitude < mindegreeslongitude) throw new argumentexception("longitude"); if (latitude > maxdegreeslatitude || latitude < mindegreeslatitude) throw new argumentexception("latitude"); _longitude = longitude; _latitude = latitude; } public distance distanceto(wgs84point that) { if (that == null) throw new argumentnullexception("that"); if (this == that) return distance.zero; var dlat = degreestoradians(latitude - that.latitude); var dlon = degreestoradians(longitude - that.longitude); var = math.sin(dlat / 2) * math.sin(dlat / 2) + math.cos(degreestoradians(latitude)) * math.cos(degreestoradians(that.latitude)) * math.sin(dlon / 2) * math.sin(dlon / 2); var c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a)); var d = distance.radiusofearth.todouble() * c; return new distance(d); } static double degreestoradians(double degrees) { return degrees * (math.pi / 180); } }
Comments
Post a Comment