How to find out distance between current geolocation coordinate and target geolocation coordinate on every tick? I want to show user how much far (in metres) he is from target object every time he walks towards the target object.

Any help plz

13 posts
• Page **1** of **2** • **1**, 2

What unit is your coordinate returned in? Or are you having trouble getting that?

https://www.ravenheart.ca/home

I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."

I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."

**Posts:**1,419**Reputation:**4,867

B

23
S

6
G

1
**Posts:**130**Reputation:**8,378

B

85
S

31
G

2
Lat. and Long. are not in meters. They are in degrees or other units.

https://www.ravenheart.ca/home

I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."

I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."

**Posts:**1,419**Reputation:**4,867

B

23
S

6
G

1
Haversine formula ?

Haversine formula:

a = sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2)

c = 2 ⋅ atan2( √a, √(1−a) )

d = R ⋅ c

where φ is latitude, λ is longitude, R is earth’s radius (mean radius = 6,371km);

note that angles need to be in radians!

Radians = Degrees * PI / 180

JavaScript:

var R = 6371e3; // metres

var φ1 = lat1.toRadians();

var φ2 = lat2.toRadians();

var Δφ = (lat2-lat1).toRadians();

var Δλ = (lon2-lon1).toRadians();

var a = Math.sin(Δφ/2) * Math.sin(Δφ/2) +

Math.cos(φ1) * Math.cos(φ2) *

Math.sin(Δλ/2) * Math.sin(Δλ/2);

var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));

var d = R * c;

**Posts:**1,519**Reputation:**11,104

B

67
S

24
G

7
korbaach wrote:Haversine formula ?Haversine formula:

a = sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2)

c = 2 ⋅ atan2( √a, √(1−a) )

d = R ⋅ c

where φ is latitude, λ is longitude, R is earth’s radius (mean radius = 6,371km);

note that angles need to be in radians!

Radians = Degrees * PI / 180

JavaScript:

var R = 6371e3; // metres

var φ1 = lat1.toRadians();

var φ2 = lat2.toRadians();

var Δφ = (lat2-lat1).toRadians();

var Δλ = (lon2-lon1).toRadians();

var a = Math.sin(Δφ/2) * Math.sin(Δφ/2) +

Math.cos(φ1) * Math.cos(φ2) *

Math.sin(Δλ/2) * Math.sin(Δλ/2);

var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));

var d = R * c;

Thanks a lot..but im just starter with construct 2..c.ant understand so much math. any simpler solution will be big big help. thanks in advance.

**Posts:**130**Reputation:**8,378

B

85
S

31
G

2
jatin1726 wrote: ..any simpler solution will be big big help.

True..so true..

here is a small example, with Browser.ExecJS : browserGeoDist.capx

(tested only in Chrome)

I tried to "translate" from javascript to C2 events...

- Code: Select all
`a = sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2)`

c = 2 ⋅ atan2( √a, √(1−a) )

d = R ⋅ c

but there is no function atan2(Y,X) in C2?!!

....or I overlooked something?

**Posts:**1,519**Reputation:**11,104

B

67
S

24
G

7
R0J0hound wrote:Instead of atan2(y,x) use angle(0,0,X,y).

Thanks @R0J0hound !

so..from

- Code: Select all
`atan2( √a, √(1−a) )`

to

- Code: Select all
`angle(0,0,sqrt(1-a),sqrt(a))*(pi/180)`

cool

--------------------------------------------

here:

Distance between London and Paris

haversine2C2.capx

**Posts:**1,519**Reputation:**11,104

B

67
S

24
G

7
13 posts
• Page **1** of **2** • **1**, 2