Page 1 of 2

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

Posted: Wed Aug 21, 2013 8:26 am
by JACKSON LIANG

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???


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

Posted: Wed Aug 21, 2013 8:58 am
by Kateryna Grynko

Hi Jackson,

Please take a look at here:
https://getsatisfaction.com/apperyio/...


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

Posted: Wed Aug 21, 2013 12:19 pm
by JACKSON LIANG

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


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

Posted: Wed Aug 21, 2013 12:36 pm
by Kateryna Grynko

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


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

Posted: Wed Aug 21, 2013 2:17 pm
by JACKSON LIANG

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.


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

Posted: Wed Aug 21, 2013 3:30 pm
by Maryna Brodina

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.


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

Posted: Thu Aug 22, 2013 2:10 am
by JACKSON LIANG

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.


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

Posted: Thu Aug 22, 2013 5:17 am
by Kateryna Grynko

Hi Jackson,

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


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

Posted: Fri Aug 23, 2013 4:04 am
by JACKSON LIANG

Thank you Katya and Marina!


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

Posted: Fri Aug 23, 2013 5:35 am
by JACKSON LIANG

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