vb.net - calculate the distance using longitude and latitude in vb using array -
i writing windows application find distance using latitude , longitude . have more 100 numbers of value in array , got formula find distance
dim theta double = lon1 - lon2 dim dist double = 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 dist = dist * 1.609344
i have arrange value lat1,lat2,lon1,lon2 ? suggestion how can arrange array pass value ?
first, decide on container store each coordinate, perhaps structure or class.
public class coordinate public latitude double public longitude double public sub new(byval lon double, byval lat double) latitude = lat longitude = lon end sub end class
then you'll need collection store of coordinates, maybe list or dictionary (if want reference them index).
public coordinates as new dictionary(of integer, coordinate)
then assignments,
coordinates.add(1, new coordinate(654.321, 123.456)) coordinates.add(2, new coordinate(321.654, 456.123))
you can build function accept custom container input.
public function calcdistance(byval coord1 coordinate, byval coord2 coordinate) double dim lon1 double = coord1.longitude dim lat1 double = coord1.latitude dim lon2 double = coord2.longitude dim lat2 double = coord2.latitude 'do math! return dist end function
finally, call function, pass values, , magic happens!
dim distancebetween double = calcdistance(coordinates(1), coordinates(2))
update: user control seems terrible place store data, i'm reluctant provide this, since it's second attempt @ posting question, here's simple way use you've got.
public function calcdistance(byval lon1 double, byval lat1 double, byval lon2 double, byval lat2 double) double 'do math! return dist end function dim distancebetween double = calcdistance(cdbl(listbox1.items(0).value), cdbl(listbox2.items(0).value), cdbl(listbox1.items(1).value), cdbl(listbox2.items(1).value))
Comments
Post a Comment