How do I calculate if I am within a radius of x meters from a given GPS point?

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Peter@multidesk.se
Posts: 136
Joined: Fri Oct 14, 2011 6:53 am

How do I calculate if I am within a radius of x meters from a given GPS point?

Post by Peter@multidesk.se » Wed Sep 11, 2019 10:36 am

I need to determine if the unit has returned to its original position to calculate the elapsed time.
This has to be done with a certain generosity as it is completely impossible to return to exactly the same position as the starting point.

Therefore, I need to set up something similar to a geo fence and then see if the unit is within this barrier, then I am back to my starting position

I would appreciate if anyone could give an example of how this could be done.


///Peter
/*Whats all the fuss with c# ?*/

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: How do I calculate if I am within a radius of x meters from a given GPS point?

Post by [-hh] » Thu Sep 12, 2019 1:36 am

Currently I am porting a great deal of geoLib ( https://github.com/manuelbieh/geolib ) to LiveCode.
Will publish it in "Sample Stacks"/livecodeshare until Sep 12 in the evening.
shiftLock happens

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9361
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: How do I calculate if I am within a radius of x meters from a given GPS point?

Post by richmond62 » Thu Sep 12, 2019 9:31 am

Why don't you start by trying something rather basic out?

Make a stack and put a graphic object that is 1x1 pixels anywhere on the stack
(frankly that is daft as the point will not be visible: make it 4x4), via the Preferences
palette write down its location on a bit of paper (retro tech).

Do the same for a second graphic object . . .

I called my first graphic "gPOINT1" and my second, "gPOINT2".

Now my "gPOINT1" is located at 407,359,

"gPOINT2" is located at 890,137.
-
skool2b.gif
-
Then we do a spot of Pythagoras . . .

Oh, and let's pretend we don't know what negative numbers are. :wink:

890-407 = 483
359-137 = 222

483 squared = 233289
222 squared = 49284

233289 + 49284 = 282573

square root 282572 = 531.576

so the linear distance (i.e. what you call the 'radius') from
"gPOINT1" to "gPOINT2" is about 532 pixels.

Of course, if you want you can do all "that" in a button in LiveCode. :D

Now it shouldn't be particularly difficult to move from that sort of stuff
to GPS points and metres. 8)

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9361
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: How do I calculate if I am within a radius of x meters from a given GPS point?

Post by richmond62 » Thu Sep 12, 2019 9:49 am

Well, I had a spot of fun . . .
-
GPS.png
-
Even if I cannot spell "Calculate." 8)

I'm sure some Freudian psychologist will come up with something
there: "caculate", "cack", enough of that one!
Attachments
JEE PEE ESS.livecode.zip
Here's the stack.
(13.8 KiB) Downloaded 175 times

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: How do I calculate if I am within a radius of x meters from a given GPS point?

Post by [-hh] » Thu Sep 12, 2019 2:06 pm

What do you expect to get when you type cmd-C or ctrl-C?
I'm not a Freudian ;-)
shiftLock happens

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9361
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: How do I calculate if I am within a radius of x meters from a given GPS point?

Post by richmond62 » Thu Sep 12, 2019 2:11 pm

What do you expect to get when you type cmd-C or ctrl-C?
Well certainly not Cack. :D

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: How do I calculate if I am within a radius of x meters from a given GPS point?

Post by [-hh] » Thu Sep 12, 2019 8:58 pm

Find the basicGeoLib (LiveCode only, no javascript) on "SampleStacks" or here
http://livecodeshare.runrev.com/stack/949/basicGeoLib
shiftLock happens

Post Reply

Return to “iOS Deployment”