|   FORUM      |     Tutoriales    |     KIO4 |      
   Start B4A (Basic4Android) App inventor 2 Arduino
   Elastix - VoIP Things of Windows Interesting Webs  Telecomunications

 


Nuevo concurso para España, Argentina, Brasil, Chile, Colombia, Ecuador, México, Perú y Portugal.

App Inventor 2
Programming mobi
le phones with Android 
by App Inventor 2 - Juan Antonio Villalpando

- Initiation Tutorial App Inventor 2 -

Return to tutorial index

____________________________

46D.- Procedures with Result (III). Distance between two points in the earth. Haversine.

- Presentation

- Let's see another Procedure whit Result.

- In principle to put instructions in the Procedure with result , we use the Block: Do a result , found in the part of Control

- You can also use local variables.

________________________________________________________________
- Calculation of the distance in kilometers between two points on the earth.


- To measure distances on the map of Google, click on a point with the right mouse button and then "Make Measurement"

- This is calculate the distance between two points on the earth to know the longitude and latitude of each.

- Keep in mind that the earth is spherical in shape. It is not entirely spherical. The terrestrial radio in Ecuador is 6378.1 km, in the Polo is 6356.8 km. The average radius is taken into 6371.0 km.

- Being a sphere we can not use the expression to calculate the distance between two points on a plane, as we did in the previous tutorial.

- The expression often used to calculate two points on the spherical surface is the formula Haversine:

Φ: latitude in radians
λ: length in radians
r: radius of the Earth, 6371 km

You can find information ...

http://www.movable-type.co.uk/scripts/latlong.html

approximate formula:

d = acos (without Φ1 Φ2 + cos without Φ1 Φ2 cos cos Δλ) R

________________________________________________________________________
________________________________________________________________________
________________________________________________________________________

I will present two examples,
one with the 46D formula Haversine and more accurate result and
another the 46E (obtained from App Inventor tutorials) worst result.

______________________________________
46D- Calculating the distance between two points Haversine.

ip46D_procedures_haversine_twopoints

- Let's create our own code using the formula Haversine.

Φ: latitude
λ: length
r: radius of the Earth, 6371 km

- I'm commenting on the Procedures with result, this code actually could have been done perfectly and without using processes more simply, the aim of using this algorithm is simply present way of introducing instructions within a Procedure.

_________________
Design


Result

_________________
Blocks

__________________________
Comments

- The formula Haversine to calculate the distance between two points on the earth knowing the latitude and longitude is:

- To facilitate the parties code breast squared I have called X and Y

- In most internet tutorials you will read that the longitude and latitude must be entered in radians, that's because in most programming languages ​​(Java, C, ...) trigonometric functions are in radians.

- In App inventor trigonometric operations (sine, cosine, tangent, ...) are made in degrees, so we will not change to radians, we'll operations in degrees.

- But ... there 's a part in that expression, the arc-sine , where the angle in radians must be obtained to be able to multiply by 2 and by 6371, so that after calculating the arc-sine (obtained in degrees), we must move that number of degrees to radians, use the block for that: convert degrees to radians .

- I'm commenting on the Procedures with result, this code actually could have been done perfectly and without using processes more simply, the aim of using this algorithm is simply discuss how to introduce statements within a procedure.

- Have you seen the way to introduce local variables and instructions within the block "Do - result ".

- Within the block "Do - result" in addition to mathematical operations, you can also be entered character string operations and properties of the components.

- Implementation of the code:

- Check results in a web:

http://www.movable-type.co.uk/scripts/latlong.html

______________________________________ ______________________________________

46E.- Calculating the distance between two points on the earth.

ip46E_procedure_distance_two_points.

- Let's calculate the distance on the sphere two points that we know its latitude and longitude.

- We're going to make in the code found in the official tutorial App inventor, although we note that a very wrong result compared with Haversine code seen above is obtained.

http://www.appinventor.org/Procedures2

_________________
Design

_________________
Blocks

__________________________
Comments

- However in the calculation it leaves a big mistake compared to Google maps. 9,000 km should leave.

_________________________________________________

 

- My e-mail:
juana1991@yahoo.com
- Who I am. - Cookies. Texts and images propierty autor:
© Juan A. Villalpando
Not copy texts neither images.
We use our own cookies and third-party cookies on our websites to maintain the session and your preferences, customize your user experience and obtain website use statistics.
Si continúa navegando consideramos que acepta su uso. OK    Más información