XY Distance

Hi,
Iโ€™m having difficulty getting Distance() to work with coordinates from two fields with the XY type. When I make two virtual columns that take these same fields and make them LatLong type, distance() functions. Can Distance() only be used with Lat/Long? Any advice? thanks!

Solved Solved
0 14 493
1 ACCEPTED SOLUTION

Thanks, I made a work around for myself. I make two virtual columns called [Location 1 X] and [Location 1 Y] and then use the expressions Lat([location 1]) and Long([Location 1]). Then I do the same for my other location [Location 2]. Then (Since I was trying to make an expression where objects wouldnโ€™t appear if their location was too far apart, I made an expression more like
Not(
Or(
OR(
([Location 1 X]-[Location 2 X))>5
,
([Location 1 X]-[Location 2 X))<-5
)
,
OR(
([Location 1 Y]-[Location 2 Y))>5
,
([Location 1 Y]-[Location 2 Y))<-5
)
)
)

View solution in original post

14 REPLIES 14

Steve
Platinum 4
Platinum 4

Yes.

Hmm, Iโ€™m not getting any result when Iโ€™m trying it. In my game I have players and Creatures. The playerโ€™s info is on its own sheet and has an XY field called [Player Character World Location]. Then in a separate sheet, I have a list of creatures and they all have an XY field called [World Creature World Location].
In the first picture, I created a virtual column on my creatures sheet that Iโ€™m trying to have measure the distance between that creature and the playerโ€™s character.

Here in the next picture, Iโ€™ve also added a virtual column called Player Location that I used the same expression in the previous picture to grab the Player Characterโ€™s XY location (just to make sure that was indeed getting the right information. But my distance is still zero. Any Advice?
3X_8_6_860602aea3e0b191d4a57916d618dc9b71644ef9.jpeg

Hi @Luke_Vancleave as you see in the Customer Support, DISTANCE() can only be computed between LatLong data types (not XY).
It calculates the distance in km.

https://www.appsheet.com/Support?q=distance&hPP=10&idx=help&p=0&is_v=1

Please read this article under โ€œMappable Typesโ€ to understand the difference between LatLong and XY.

@Steve XY() and Distance() should be updated

Thanks, I made a work around for myself. I make two virtual columns called [Location 1 X] and [Location 1 Y] and then use the expressions Lat([location 1]) and Long([Location 1]). Then I do the same for my other location [Location 2]. Then (Since I was trying to make an expression where objects wouldnโ€™t appear if their location was too far apart, I made an expression more like
Not(
Or(
OR(
([Location 1 X]-[Location 2 X))>5
,
([Location 1 X]-[Location 2 X))<-5
)
,
OR(
([Location 1 Y]-[Location 2 Y))>5
,
([Location 1 Y]-[Location 2 Y))<-5
)
)
)

Here is what you can do:
Add a Virtual Column with Type LatLong with the expression:
LATLONG(LAT([XY]),LONG([XY]))

Then you can use the DISTANCE() expression.

I donโ€™t know how much sense this makes for your usecase, but you can try

I tried that initially but this ran into a distortion because the coordinates of an XY are a grid on a flat plane and the coordinates of LatLong are on a sphere (where things get distorted more towards the poles). you can see my other reply here for my work around.

Awesome @Steve I learned this when I was 15 years old and didnโ€™t remember

Very cool @Luke_Vancleav. May I ask you to share some screenshots of your App?
Sounds like an interesting XY usecase.

Absolutely!
So Iโ€™m trying to make an RPG sorta game inspired by a loose role play group I was a part of like ten years ago. I wanted to create a world that playerโ€™s characters could physically exist in with non player entities and mechanics.

One of these was that I wanted playerโ€™s characters to be able to โ€œHuntโ€ prey but to gamify this I wanted prey to only appear if they were within โ€œSight Distanceโ€ of the player. So I have one table of Player Characters with XY coordinates and another table of Prey with XY coordinates (which adds new rows daily to replenish numbers of prey).

So I needed to make the Show? expression for the Prey[XY] have an expression based on the distance between them and the player. So I came up with this solution.
Itโ€™s still not ideal because Distance() calculates things in a radius (which I would prefer and might need for other applications) and this method checks in a square around the Player Character.

Your map view looks like the usual Google Maps Aerial view.
But you say you are using XY. So did you take a Screenshot from Google Maps Aerial View and use this image as the XYโ€™s Background image?
Why donโ€™t you use LatLong column type? I donโ€™t see the need of XY here, but Iโ€™m happy to learn

Ah, that would be a little confusing. Iโ€™m using this image as a stand-in until I have one of my artist friends create a game world map to have it set in. This particular image is nice because itโ€™s high resolution so while it cover the area of about a mile square, I can zoom into an area around a city block without it getting blurry. Iโ€™m still working out what scale I want the game world to operate in.

You can use DISTANCE() with XY values. You just have to convert them to LatLong.

If I recall I tried something similar when I was still working on this project. But lat/long wasnโ€™t directly comparable to XY because XY is describing a flat grid and LatLong is a point on a globe. So the result would be more skewed than you might think it would be

Top Labels in this Space