Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Studio Chat / Coordinates to km (or miles)

Author
Message
jlahtinen
14
Years of Service
User Offline
Joined: 26th Oct 2009
Location: Finland
Posted: 27th Jul 2021 12:03
I tested few formulas to convert map coordinates to distance in km, but all formulas return 0 in AGK.



What I am doing wrong here?

Original:

Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 27th Jul 2021 12:52 Edited at: 27th Jul 2021 13:11
where were values given to the lat's and lon's ???

If those values are zero , then the result of that formula will be zero.

Yes there are other numbers being given in the formula (6371 and the 0.174...), but those rad's are being multiplied by the lon's and lat's before they computed otherwise, so they would be zeros before the other additions, subtractions etc are being done, leaving you adding and subtracting zeros, leaving a zero to multiply by the 6371, again resulting in zero.


EDIT
I just ran a test on the first snippet, and I did get results other than zero once I gave values to the lat's and lon's

So, you should be okay if you make sure all of those <> 0 before doing the calculation.

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
jlahtinen
14
Years of Service
User Offline
Joined: 26th Oct 2009
Location: Finland
Posted: 27th Jul 2021 13:11
Ofcourse the values must be given...

Whole code:



For example these values give: "-nan(ind)"
Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 27th Jul 2021 13:20 Edited at: 27th Jul 2021 13:49
Of course..lol

The problem with those values is the lon2 seems to be messing it up.

If I reduce that value then it works, so it is somehow throwing it out of range?

I am not good with the cos and sin formulas..

Sorry I couldn't help.

EDIT

I used whole numbers on the lon's and lat's and reduced the length of the rad's digits and got better results

So maybe the length of those is what is throwing it our of range... not sure why if the lengths are fixed for floats, but it did not give the "-nan(ind)" result

Tried it again with the full length rad using whole numbers for long and lat and didn't get the " -nan(ind)"

I tried once again leaving the full length of all numbers, but removed the decimal thus making the longs and lats huge and it still did not give the "-nan(ind)" result

So, you may want to use whole numbers to keep this in range of the math capabilities then place those decimals yourself afterwards

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 27th Jul 2021 13:44 Edited at: 27th Jul 2021 14:02
converting this:

seems to work?
[My Itch.io Home] [Community Apps on Itch.io]
[AGK Resource Directory] [TGC @ GitHub]
[CODE lang=agk] YOUR CODE HERE [/CODE]
[VIDEO=youtube] VIDEO ID [/VIDEO]
[AGK Showcase][Google Forum Search]
jlahtinen
14
Years of Service
User Offline
Joined: 26th Oct 2009
Location: Finland
Posted: 27th Jul 2021 13:45
Yeah, with some coordinates it gives some results (but not right).

Tried 3 different formulas and none of them work with AGK. AppGameKit precision error maybe... I have no idea.


Another:

https://www.geeksforgeeks.org/program-distance-two-points-earth/
jlahtinen
14
Years of Service
User Offline
Joined: 26th Oct 2009
Location: Finland
Posted: 27th Jul 2021 13:49
Quote: "converting this:

+ Code Snippet
seems to work?"


This works fine!

Massive thanks, I'll bet this is useful to others too.

Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 27th Jul 2021 13:57 Edited at: 27th Jul 2021 14:03
double-check it where i'm still on my first cup of coffee this morning

otherwise, i've never played with this but i'm seeing lat/lon using north/south & e/w so how does this account for that?

then, with your original post, whenever i see integers mixed with floats i get nervous that something is being cast as an integer. not saying that was the issue with yours but best habit when expecting to return floats is to use all floats. (just edited my code above to use "all" floats. i'd missed a couple )
[My Itch.io Home] [Community Apps on Itch.io]
[AGK Resource Directory] [TGC @ GitHub]
[CODE lang=agk] YOUR CODE HERE [/CODE]
[VIDEO=youtube] VIDEO ID [/VIDEO]
[AGK Showcase][Google Forum Search]
Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 27th Jul 2021 14:02 Edited at: 27th Jul 2021 14:08
EDIT
Never mind...

Virtual Nomad already found a solution.


My work around would not have been any good anyway, now that I see that longitudes and latitudes are not uniform units of measure.

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
jlahtinen
14
Years of Service
User Offline
Joined: 26th Oct 2009
Location: Finland
Posted: 27th Jul 2021 18:47
Quote: "longitudes and latitudes are not uniform units of measure."


Yes, it's pain.

Quote: "double-check it where i'm still on my first cup of coffee this morning

otherwise, i've never played with this but i'm seeing lat/lon using north/south & e/w so how does this account for that?

then, with your original post, whenever i see integers mixed with floats i get nervous that something is being cast as an integer. not saying that was the issue with yours but best habit when expecting to return floats is to use all floats. (just edited my code above to use "all" floats. i'd missed a couple )"


Actually this formula is off also, like 10km in 30km distance when comparing to Google maps (you can measure direct distance with right mouse click). Not your mistake ofcourse.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 28th Jul 2021 03:20
Quote: "Actually this formula is off"

after i read THIS, i claim THIS

meanwhile, the Haversine Formula above "determines the great-circle distance between two points on a sphere given their longitudes and latitudes. Important in navigation", it's seemingly obvious that it's use is "earthly" (while earth is not a perfect sphere - which i doubt google maps contemplates but it may be considering changes in elevation/undulation which would affect the "driving distance" it's generally used for).

being off "10km in 30km distance" is unacceptable but i personally don't know where to go from here...

if you find a formula (that you agree with since it appears you want it to agree with google maps), i would be happy to help convert to AppGameKit, otherwise
[My Itch.io Home] [Community Apps on Itch.io]
[AGK Resource Directory] [TGC @ GitHub]
[CODE lang=agk] YOUR CODE HERE [/CODE]
[VIDEO=youtube] VIDEO ID [/VIDEO]
[AGK Showcase][Google Forum Search]
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 28th Jul 2021 04:22
I wonder if the google maps api has a function for this?
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 28th Jul 2021 04:44 Edited at: 28th Jul 2021 04:53
Quote: "I wonder if the google maps api has a function for this?"

all that i see is the distance matrix which follows routes (vs a straight line).
Quote: "If you pass latitude/longitude coordinates, they will snap to the nearest road. "


same for OSMR which i may tinker with since i dont believe it requires an API key.
[My Itch.io Home] [Community Apps on Itch.io]
[AGK Resource Directory] [TGC @ GitHub]
[CODE lang=agk] YOUR CODE HERE [/CODE]
[VIDEO=youtube] VIDEO ID [/VIDEO]
[AGK Showcase][Google Forum Search]
Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 28th Jul 2021 11:56 Edited at: 28th Jul 2021 12:09
Earlier, I had suggested just using vector distance like you would two points on a 2d representation such as our screen .

Then, I realized that the longitudes are only uniform at the equator,

So, the vector thing wouldn't work unless you plot off the four unions forming a trapezoid for that section using an array or table of the distances between each point.

Then you could do some triangulation off the corners.

Yeah the earth is not a perfect sphere, but each distance between two longitude lines (meridians) should be uniform for each latitude (generally speaking) so you wouldn't need values for every one, just one value for them all for each latitude. (vice versa)

Search "table of differences in distance for longitudes" to find more info to build your array. (or keep searching for a formula that gives accurate results)

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
jlahtinen
14
Years of Service
User Offline
Joined: 26th Oct 2009
Location: Finland
Posted: 31st Jul 2021 13:26
Yeah, it's weird claiming that the formula is +-0.5% accurate if it depends being near equator (or something). It's more baffling that basically everyone on stackoverflow agrees and claims it's accurate (and I cant post there, need some "reputation" or something, dont care).

Have to keep digging into it.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 1st Aug 2021 14:49
Have you looked at this?
http://edwilliams.org/avform147.htm

I guess that's what they used to build the calculator on this site: https://www.nhc.noaa.gov/gccalc.shtml?
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Login to post a reply

Server time is: 2024-04-19 02:51:33
Your offset time is: 2024-04-19 02:51:33