Hello everyone, I'm using live code to develop an app that shows the current latitude and longitude of a device and location from the chosen destination latitude and longitude everything is working perfectly in the second try but it doesn't display data on the first try and by try I mean clicking the button in the IOS simulator the first click not the data I want empty data in the second click it displays the data, the code I'm using is this
on mouseUp
if the environment is "mobile" then
mobileStartTrackingLocation
end if
put mobileCurrentLocation() into theLocation
put theLocation["latitude"] into testLat
put theLocation["longitude"] into testLong
put testLat into field "lat"
put testLong into field "long"
put 24.197436 into plat2
put 55.677981 into plon2
put testLat / 180 * pi into LVRadLat1
put testLong / 180 * pi into LVRadLong1
put plat2 / 180 * pi into LVRadLat2
put plon2 / 180 * pi into LVRadLong2
put RFHaversine (LVRadLat1,LVRadLong1,LVRadLat2,LVRadLong2) & " KM" into field Distance
end mouseUp
Function RFHaversine PVLat1,PVLong1,PVLat2,PVLong2
set numberFormat to 0.000000000000 -- Heavy precision required here !
put 6367 into LVRadiusOfTheEarth -- Generally accepted Radius of the Earth
put PVLat1 into LVLat1
put PVLong1 into LVLong1
put PVLat2 into LVLat2
put PVLong2 into LVLong2
put LVLong2 - LVLong1 into LVInt1
put LVLat2 - LVLat1 into LVInt2
put (sin(LVInt2/2))^2 + cos(LVLat1) * cos(LVLat2) * (sin(LVInt1/2))^2 into LVWork1
put 2 * atan2(sqrt(LVWork1),sqrt(1-LVWork1)) into LVWork2
put LVRadiusOfTheEarth * LVWork2 into LVWork3
--
-- We now have the distance in kilometres in LVWork3.
--
put round(LVWork3,2) into LVWork3
return LVWork3
end RFHaversine