Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
hsh_636
- Posts: 31
- Joined: Sun Mar 02, 2014 5:15 pm
Post
by hsh_636 » Sun Mar 09, 2014 12:07 pm
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
Code: Select all
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
thanks in advance for the help.
-
Klaus
- Posts: 14213
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Sun Mar 09, 2014 1:09 pm
Hi hsh_636,
a shot in the dark:
Maybe "mobileStartTrackingLocation" takes a while to start and you can "outsource" these lines to an "opencard" script?
Code: Select all
on opencard
if the environment = "mobile" then
mobileStartTrackingLocation
end if
end opencard
And leave these lines out in your mouseup handler:
Code: Select all
on mouseUp
if the environment <> "mobile" then
exit mouseup
end if
put mobileCurrentLocation() into theLocation
...
At least worth a try
Best
Klaus
-
hsh_636
- Posts: 31
- Joined: Sun Mar 02, 2014 5:15 pm
Post
by hsh_636 » Sun Mar 09, 2014 2:06 pm
thanks I'll try it and hopefully it will work.
-
hsh_636
- Posts: 31
- Joined: Sun Mar 02, 2014 5:15 pm
Post
by hsh_636 » Sun Mar 09, 2014 2:57 pm
Thanks Mr. Klaus it totally worked, you're a genius.
-
Klaus
- Posts: 14213
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Sun Mar 09, 2014 7:50 pm
hsh_636 wrote:Thanks Mr. Klaus it totally worked, you're a genius.
Yes, I hear that often these days...

-
SparkOut
- Posts: 2949
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Sun Mar 09, 2014 8:22 pm
If the hat fits, wear it!
although... if you hear this too much you may get big headed - and then the hat wouldn't fit!
(but it's a pretty big hat, I don't think you have much to worry about)