Visa ett inlägg
Oläst 2008-04-01, 00:03 #4
Roberts avatar
Robert Robert är inte uppkopplad
Klarade millennium-buggen
 
Reg.datum: Jan 2004
Inlägg: 2 103
Robert Robert är inte uppkopplad
Klarade millennium-buggen
Roberts avatar
 
Reg.datum: Jan 2004
Inlägg: 2 103
Uhm, har en gammal kod för detta, dock i vb.net, men det ska väl inte vara alltför svårt att se hur man gör?:

Kod:
Public Function nGetDistance(ByVal nLat1 As Double, ByVal nLong1 As Double, ByVal nLat2 As Double, ByVal nLong2 As Double) As Double
	'Returns the distance in kilometers between two set of coordinates. Coordinates must be converted to decimals first (use sDegreesToDecimalPos())
	Const kEarthRadiusKms As Double = 6376.5
	Dim nDistance As Double = Double.MinValue
	Dim nLat1InRad As Double = nLat1 * (Math.PI / 180)
	Dim nLong1InRad As Double = nLong1 * (Math.PI / 180)
	Dim nLat2InRad As Double = nLat2 * (Math.PI / 180)
	Dim nLong2InRad As Double = nLong2 * (Math.PI / 180)
	Dim nLongitude As Double = nLong2InRad - nLong1InRad
	Dim nLatitude As Double = nLat2InRad - nLat1InRad
	Dim a As Double = Math.Pow(Math.Sin(nLatitude / 2), 2) + Math.Cos(nLat1InRad) * Math.Cos(nLat2InRad) * Math.Pow(Math.Sin(nLongitude / 2), 2)
	Dim c As Double = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a))
	nDistance = kEarthRadiusKms * c
	Return nDistance
End Function


Public Function sConvert_DegreesToDecimalPos(ByVal nDegrees As Int32, ByVal nMinutes As Int32, ByVal nSeconds As Int32) As Decimal
	'Converts the recieved NMEA(WGS-84) location to a decimal number. (DEGREES+(MINUTES+(SECONDS)/60)/60)
	Return nDegrees + (nMinutes + (nSeconds) / 60) / 60
End Function
Robert är inte uppkopplad   Svara med citatSvara med citat