I did this update code… but i am not getting the right direction yet
[lua]
local point1 ={}
local point2 ={}
point2.x = 21.45
point2.y = 39.81
–23.608234, 58.527350
–point1.latitude = 23.608234
–point2.longitude = 58.527350
–26.402426, 29.410834
–point1.x = 26.4024
–point1.y = 29.41
local compassPointer = display.newImage(‘images/pointer.png’)
compassPointer.anchorX = 0.5
compassPointer.anchorY = 0.5
compassPointer.x = display.contentCenterX
compassPointer.y = display.contentCenterY
local function updateCompass( event )
--print( "Compass magnetic: " … event.magnetic )
compassHeading = event.magnetic
if compassHeading == -1 then
print(“no heading”)
return
end
local deltaAngle = math.floor(angle - compassHeading)
if deltaAngle < 0 then
deltaAngle = deltaAngle + 360
end
print(“angle:”, angle, “compass”, compassHeading, “deltaAngle:”, deltaAngle, compassHeading - angle)
compassPointer.rotation = (deltaAngle)
end
local function angleBetween( point1, point2 )
local angle = ( math.deg( math.atan2( point2.y - point1.y, point2.x - point1.x ) ) + 90 )
return angle % 360
end
local distanceBetween – function to find distances between the two porints
function distanceBetween( point1, point2 )
local dX = point2.longitude - point1.longitude
local dY = point2.latitude - point1.latitude
local distance = math.sqrt( ( dX^2 ) + ( dY^2 ) )
return distance
end
----- variabel to show the distance between my location and
local angleNow = display.newText( “-”, 100, 50, native.systemFont, 16 )
local latNow = display.newText( “-”, 100, 100, native.systemFont, 16 )
local LongNow = display.newText( “-”, 100, 150, native.systemFont, 16 )
----- handler for location handler
local locationHandler = function( event )
– Check for error (user may have turned off location services)
if ( event.errorCode ) then
native.showAlert( “GPS Location Error”, event.errorMessage, {“OK”} )
print( "Location error: " … tostring( event.errorMessage ) )
else
point1.x = event.latitude
point1.y = event.longitude
point1.latitude = event.latitude – set my lat
print ("point1.latitude = " … point1.latitude)
latNow.text = event.latitude
point1.longitude = event.longitude – set my long
print ("point1.longitude = " … point1.longitude)
LongNow.text = event.longitude
--print(point1.latitude,point1.longitude)
--local x = distanceBetween(point1,point2) – find differnace…
--local diff = string.format( ‘%.1f’, x ) – format it to one decimal
--print (" the distance is " …diff)
--distance.text = diff
--drawLine(point1,point2)
angle = angleBetween( point1, point2 )
angleNow.text = angle
end
end
–angle = angleBetween( point1, point2 )
Runtime:addEventListener( “location”, locationHandler ) – to get my location
Runtime:addEventListener( “heading”, updateCompass ) – to rotate the compass
[/lua]