JACKSON LIANG
Posts: 0
Joined: Fri Aug 02, 2013 5:12 am

how to calculate distance using longitude and latitude between two points on a custom googlemap?

Hi im trying to calculate the distance using the longitude and latitude between two points and display it how do i do this on javascript???

JACKSON LIANG
Posts: 0
Joined: Fri Aug 02, 2013 5:12 am

how to calculate distance using longitude and latitude between two points on a custom googlemap?

Hi Katya, how do i change the code so that i can display the distance on a label and call on this function?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

how to calculate distance using longitude and latitude between two points on a custom googlemap?

Jackson,

Add the function described above as a JavaScript asset, then run the following JavaScript code when needed:
codeAppery( "mobilelabel_result" ).val( distance(
Appery( "mobilelabel_from_lat" ).val(), Appery( "mobilelabel_from_long" ).val(),
Appery( "mobilelabel_to_lat" ).val(), Appery( "mobilelabel_to_long" ).val()
) );/code

JACKSON LIANG
Posts: 0
Joined: Fri Aug 02, 2013 5:12 am

how to calculate distance using longitude and latitude between two points on a custom googlemap?

Hi Katya, I have followed the instructions but it doesnt seem to work. I copied and pasted the code on a javascript file and named it 'test'. I then tried to execute the function with the code u just provided using a button.

and renamed it to the following code:

Appery( "mobilelabel_result" ).val( distance(
Appery( "latitude" ).val(), Appery( "longitude" ).val(),
Appery( "lat_test1" ).val(), Appery( "long_test2" ).val()
) );

'latitude' and 'longitude' is my current locations position.
'lat_test1' and 'long_test2' was a random position

all four values were in an input box.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

how to calculate distance using longitude and latitude between two points on a custom googlemap?

Hello!
1) If you saves result in Label you need to use codeAppery( "mobilelabel_result" ).text/code instead codeAppery( "mobilelabel_result" ).val/code
2) What are 'latitude', 'longitude', 'lat_test1' and 'long_test2' components?
if they are Inputs - then the code is correct, if they are Labels - use method text instead of val
3) try this code:
codeAppery( "mobilelabel_result" ).text( distance(
+Appery( "latitude" ).val(), +Appery( "longitude" ).val(),
+Appery( "lat_test1" ).val(), +Appery( "long_test2" ).val()
) );/code
unary plus converts a string to a number.

JACKSON LIANG
Posts: 0
Joined: Fri Aug 02, 2013 5:12 am

how to calculate distance using longitude and latitude between two points on a custom googlemap?

Hi Marina, that worked perfectly thank you very much. However i forgot to mention that for the distance i want it to be in km not in miles since my country doesnt use miles. So for the code Katya had provided for me what do i need to change to make the function calculate in terms of km.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

how to calculate distance using longitude and latitude between two points on a custom googlemap?

Hi Jackson,

Then you can remove the division by the number of kilometers to miles ratio: code/ 1.60933966531/code

JACKSON LIANG
Posts: 0
Joined: Fri Aug 02, 2013 5:12 am

how to calculate distance using longitude and latitude between two points on a custom googlemap?

How do i round it to two decimal places. its giving me like 85.08850817788226 .

Return to “Issues”