1

have not programed any of the location services so let me describe my problem and you can tell me if location services can help or not.

I have one mobile user1(long1, lat1, altitude1) that wants to face another mobile user2(long2, lat2, altitude2).

Altitude is optional.

I want to provide feedback to user1: left/right (<- ->), tilt up/down (^ v) until the top of the device is pointing at user2.

User2 could be anywhere on the globe.

In a nutshell: Calculate direct line of site (you CAN see through the earth) between 2 devices then provide feedback (directional arrows) to put the device on the line of site.

All pointers are appreciated.

Gabriel.Massana
  • 8,165
  • 6
  • 62
  • 81
KingAndrew
  • 1,164
  • 4
  • 21
  • 41

1 Answers1

0

Neither iOS nor Android provide this kind of functionality. It's not really a desired function when dealing with determining distance for our travels across the world in the majority of use cases.

But, you can using 3D maths to calculate this angle and distance.

To do so you first need to plot the lat/long locations on a sphere in 3D space which is approximately comparable in size to the earth (or scaled, where you have an accurate distance scale).

You will lose accuracy performing this calculation for the following reasons:

  • Because the earth is not a true sphere
  • By excluding altitude you're losing more accuracy
  • If the spherical size isn't equivalent to of earths size (you could also scale it down and extrapolate)
  • If your unit of distance is not accurate for the sphere (if the sphere is scaled)

Then once you have the two points on a sphere (in 3D space), you can then calculate the shortest distance between then using the Pythagorean theorem (twice).

Below are two SO links which specifically cover the 3D math needed to do this now that you have your lat/long plotted in 3D space.

Related Links:

Community
  • 1
  • 1
Joshua Briefman
  • 3,783
  • 2
  • 22
  • 33