# JavaScript App Inventor. Block: WebViewStringChange (WebView component)

850 views

### Juan Antonio

Jul 12, 2018, 12:24:45 PM7/12/18
Hi friends,

from Built: July 11 2018  Version: nb169 we have the event block WebViewStringChange (in WebViewer component), with this block is easy work with JavaScript.

Here an example: calculate the module of a 3D vector.

AI2 code sends 18.5:14.7:7.3 to htm file with JS, and JS code split numbers (":"), calculate and return result to block WebViewStringChange.

http://kio4.com/appinventor/167_javascript_vector_3d.htm (It is in Spanish)

More tutorials about JavaScript and App Inventor (Spanish): http://kio4.com/appinventor/index.htm#javascript

- Regards.

- Juan A. Villalpando

p167i_javascript_vector_3d.aia

### Juan Antonio

Jul 12, 2018, 12:46:06 PM7/12/18
to MIT App Inventor Forum
This is other example:

AI2 sends 2 numbers 56.23:60 and gets 2 numbers 28.11:48.69

http://kio4.com/appinventor/167B_javascript_vector_2d.htm (It is in Spanish)

### Juan Antonio

Jul 12, 2018, 1:15:04 PM7/12/18
Why do we use JavaScript in AI2?

- if we need a simple code (calculate module, angle,...) we can use AI2 blocks,

- but now we need calculate geodetic distance between two points specified by latitude and longitude using the Vincenty method.

Vincenty's solution for the distance between points on an ellipsoidal earth model is accurate to within 0.5 mm distance (!), 0.000015? bearing, on the ellipsoid being used. Calcula­tions based on a spherical earth model, such as the (much simpler) Haversine , are accurate to around 0.3% – which is still good enough for many (most?) purposes, of course.

but Taddeus Vincenty' solution is a long algoritm:

we can use JavaScript code in a htm file, and send/get data.

- JS Code in attached .aia

p169Pi_javascript_distancia.aia

### SteveJG

Jul 12, 2018, 3:02:17 PM7/12/18
to MIT App Inventor Forum
Nice implementation of the Vincenty Direct formula Antonio.   The results are identical to what is determined on movable-type's web page calculator for identical coordinates.

The Vincenty model uses an ellipsoidal model that is supposedly accurate to within a few millimeters when calculating the distance between two known geocoordinates.  Does this mean distance measurements using the LocationSensor and GPS hardware are more accurate if you use it over a spherical model?  Certainly not, the best precision of the GPS receivers in phones is on the order of two METERS at best.  Usually the accuracy  can easily vary from one satellite fix to the next from +/- 2 to 50 meters or more away from the actual coordinates depending on how many satellites are used in the fix and the quality of the GPS hardware in a device (see a discussion of Accuracy in the LocationSensor tutorial).

Beautiful demonstration of the new WebViewChange.  This is a significant feature to App Inventor by MIT.  Thanks for demonstrating how easy it is to use the new Block.  There is a lot of JavaScript code available on the Internet that can be modified in a similar way.  Thanks.

Regards,
SteveJG

### Abraham Getzler

Jul 12, 2018, 3:46:54 PM7/12/18
to MIT App Inventor Forum
(added to WebView section of FAQ)
ABG

### Taifun

Jul 12, 2018, 4:08:39 PM7/12/18
to MIT App Inventor Forum
don't forget to adjust the path to the html file ...

Yes, you also can upload html files as assets into App Inventor! There is only one special thing to consider: During development, you have to use the development path to the embedded html document:

`file:///mnt/sdcard/AppInventor/assets/<NAME OF YOUR HTML FILE>.html`

Before packaging the app, use the production path.

`file:///android_asset/<NAME OF YOUR HTML FILE>.html`

The tools extension offers the method PathToAssets which always returns the correct path to the assets.

Taifun