  Discussion in 'Additional libraries, classes and official updates' started by derez, Mar 26, 2012.

Convert GEO coordinates to UTM and vice versa.
Calculate the length of a route (a sequence of waypoints)
Calculate the area of a polygon defined by a sequence of waypoints, and btw
Calculate distance and bearing from one point to the other.

The sets of point can be defined either as an array or by a list.
The file contains a demo program.

Have fun Edit: Ver 1.1 with two additional methods, GeoNextPoint and UTMNextPoint.
Edit: Version 1.2 fixes a bug in SphericalArea and SphericalArea2 methods.

#### Attached Files:

File size:
8.6 KB
Views:
541
File size:
6.7 KB
Views:
18
Last edited: Jun 9, 2019
06 Juan, Almora, asales and 6 others like this.
2. So sorry to say something

I am very interested in the "navigation" LIB ,but I have no right to download it . So can I ask you to send me a copy to my E-mail
()

Think you !:sign0098:

3. if you have no right to download it then you have no right to use it.

4. Nor can he use it. The demo software won't use libraries.

5. Darez,

If i wanted to get the range and bearing from one position to another (co-ordinates are in latitude and longitude), how would i use this library???

Is the a break down of the syntax and commands inculding variable types used

Thanks

6. If you need only the distance bearing function you don't need this library, you can use Location.

To use the function put the coordinates of the first point and the second point as parameters and get the returned values into an array of doubles, the first will be distance, the second - bearing.

example:
First - initialize the library object, here - nav
Code:
`Dim dbl() As Doubledbl = nav.GeoDistanceBearing(first.Lat,first.Lon,second.Lat,second.Lon)distance.Text =  dbl(0)bearing.Text =  dbl(1)`

Last edited: Oct 25, 2012
7. Thanks i will give it a go 8. Hi,

Is it also possible to use this library to calculate location B, knowing location A, distance and bearing?
And how would i implement that?

This would be extremely helpfull for my project 9. At the moment the library doesn't support it, but I've found this algorithm here
Aviation Formulary V1.46

Code:
`'Lat/lon given radial and distance'A point {lat,lon} is a distance d out on the tc radial from point 1 if:lat=asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc))IF (cos(lat)=0)        lon=lon1      // endpoint a poleELSE        lon=mod(lon1-asin(sin(tc)*sin(d)/cos(lat))+pi,2*pi)-piENDIF`
and I'll add it to the library soon.

Edit : last line should be
Code:
`lon=mod(lon1 + asin(sin(tc)*sin(d)/cos(lat))+pi,2*pi)-pi`

Last edited: Oct 27, 2012
10. Library updated to ver 1.1 with two new methods:
- GeoNextPoint
-UTMNextPoint
Calculating the coordinates of a point by distance and bearing from a known point.

The formula above is wrong !, the last line should be
Code:
`lon=mod(lon1 + asin(sin(tc)*sin(d)/cos(lat))+pi,2*pi)-pi`
but I used the more general formula for long2:
Code:
`double dlon = Math.atan2(Math.sin(Bearing) * Math.sin(Distance)                          * Math.cos(Lat1), Math.cos(Distance)                           - Math.sin(Lat1) * Math.sin(Lat2)) ;double Long2 = ( Long1 +  dlon + Math.PI) % (2*Math.PI ) - Math.PI ;`

nemiroG1 likes this.
11. How does GeoNextpoint output?

Output.GeoNextPoint(52.1234,5.05,100,180) ??

I want to use 2 variables "Lattitude" and "longitude" how to get them seperately?

Last edited: Nov 6, 2012
12. The method returns an array of the two required variables, here is an example:
Code:
`Sub Gnext_ClickDim dbl() As Doubledbl = nav.GeoNextPoint(52.1234,5.05,100,180)latlbl.Text = dbl(0)   'or use this: = NumberFormat(dbl(0),1,3)longlbl.Text = dbl(1) 'or use this: = NumberFormat(dbl(1),1,3)   End Sub`

13. Aha! ok, im going to play with that tomorrow I gues the lattitude and Longitude are in Decimal degrees? not DDMMSS?

14. Yes, Decimal Degrees.

Hi Derez,

I run the Navigation tutorial video on
05. Tutorial Basic4Android - Uso del GPS.mp4 - YouTube

and try to implement same in B4A program but below error is showing and out put is not showing as per tutor video.
------------------------------------------------------------------------
Parsing code. 0.00
Compiling code. 0.09
Compiling layouts code. 0.00
Generating R file. 0.09
Compiling generated Java code. Error
B4A line: 58
lbl_info.Text=\
javac 1.7.0_17
src\b4a\example\main.java:321: error: no suitable method found for NumberToString(double[])
mostCurrent._lbl_info.setText((Object)("UTM:"+BA.NumberToString(mostCurrent._nav.LatLonToUTM(6378137.0,1/(double)298.257223563,mostCurrent._loction1.getLatitude(),mostCurrent._loction1.getLongitude()))));
^
method BA.NumberToString(long) is not applicable
(actual argument double[] cannot be converted to long by method invocation conversion)
method BA.NumberToString(int) is not applicable
(actual argument double[] cannot be converted to int by method invocation conversion)
method BA.NumberToString(double) is not applicable
(actual argument double[] cannot be converted to double by method invocation conversion)
1 error
_________________________________________________

line no 58 is

lbl_info.Text="Lat:"&Loction2.ConvertToSeconds(Loction2.Latitude)&" Long:"&Loction1.ConvertToSeconds(Loction1.Longitude)
lbl_info.Text="UTM:"&nav.LatLonToUTM(6378137.0,1/298.257223563,Loction1.Latitude,Loction1.Longitude)

Pls. suggest what to do to proceed with this program.

Best Regards
Nitin :sign0085:

16. Please use [ code ] [ /code ] tags (without spaces) when posting code.

I guess that nav.LatLonToUTM returns an array with two doubles:
Code:
`Dim ll() As Double = nav.LatLonToUTM(...)lbl_info.Text = "UTM: " & ll(0) & ", " & ll(1)`

Navigation tutorials and Gps sample program issue

Hi Erel,

Thanks for the same.
Now I have changed the UTM output parameter data types to double array as per your reply and the modified code is as follows:

Sub gps_LocationChanged(Loction1 As Location)
Dim ll() As Double = nav.LatLonToUTM(6378137.0,1/298.257223563,Loction1.Latitude,Loction1.Longitude)
lbl_info.Text = "LAT:" & Loction1.Latitude & ", " & "LON:" & Loction1.Longitude & ", " & "UTM: " & ll(0) & ", " & ll(1)
End Sub

But on gps_LocationChanged event the result is not showing in label (lbl_info.Text) so I write below code on label/button click event as follows:

Sub lbl_info_Click
Dim ll() As Double = nav.LatLonToUTM(6378137.0,1/298.257223563,Loction2.Latitude,Loction2.Longitude)
Msgbox(Loction2.Latitude ,"Latitude")
Msgbox(Loction2.Longitude ,"Longitude")
Msgbox(NumberFormat(ll(0),1,3) ,"UTM1")
Msgbox( NumberFormat(ll(1),1,3) ,"UTM2")
End Sub

And the out put is
Latitude=0
Longitude=0
UTM1 =833,979.011
UTM2 =0.5

Why the Latitude & Longitude is showing 0 output and not changing to any non zero value like the navigation tutor output
05. Tutorial Basic4Android - Uso del GPS.mp4 - YouTube

Shall I need to pass Latitude & Longitude manually to this nav.LatLonToUTM() function ? Give me some sample B4A code or documentation to get the Latitude & Longitude or GPS position of my android cell phone.

Pls. suggest !:sign0085:

Best Regards
Nitin

18. Does the LocationChanged event fire? Are you testing the GPS outdoors?

Navigation tutorials and Gps sample program issue

Hi erel,

I am testing the GPS outdoors even on terrace of my office as well as at my residence. I think LocationChanged event is not fired and the label click event below gives output for UTM only & no result for Lat & lon .

Sub lbl_info_Click
Loction2.Initialize
Dim ll() As Double = nav.LatLonToUTM(6378137.0,1/298.257223563,Loction2.Latitude,Loction2.Longitude)
Msgbox(Loction2.ConvertToSeconds(Loction2.Latitude) ,"Latitude")
Msgbox(Loction2.ConvertToSeconds(Loction2.Longitude) ,"Longitude")
Msgbox(NumberFormat(ll(0),1,3) ,"UTM1")
Msgbox( NumberFormat(ll(1),1,3) ,"UTM2")
End Sub

output is as follows:
Latitude=0:0:0
Longitude=0:0:0
UTM1=833,979.011
UTM2=0.5

What will be reason for not showing Latitude & Longitude?