B4A Library Navigation Library

Here is a library to help in navigation tasks:
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.
 

Attachments

  • Navigation_example.zip
    8.6 KB · Views: 1,143
  • Navigation_1.2.zip
    6.7 KB · Views: 646
Last edited:

oldpig1989

New Member
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
()

So appreciate your kindness!

Think you !:sign0098:
 

barx

Well-Known Member
Licensed User
Longtime User
if you have no right to download it then you have no right to use it.
 

Stulish

Active Member
Licensed User
Longtime User
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
 

derez

Expert
Licensed User
Longtime User
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
B4X:
Dim dbl() As Double
dbl = nav.GeoDistanceBearing(first.Lat,first.Lon,second.Lat,second.Lon)
distance.Text =  dbl(0)
bearing.Text =  dbl(1)
 
Last edited:

Stulish

Active Member
Licensed User
Longtime User
Thanks i will give it a go :)
 

PD5DJ

Member
Licensed User
Longtime User
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 :)
 

derez

Expert
Licensed User
Longtime User
At the moment the library doesn't support it, but I've found this algorithm here
Aviation Formulary V1.46

B4X:
'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 pole
ELSE
        lon=mod(lon1-asin(sin(tc)*sin(d)/cos(lat))+pi,2*pi)-pi
ENDIF

and I'll add it to the library soon.

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

derez

Expert
Licensed User
Longtime User
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
B4X:
lon=mod(lon1 + asin(sin(tc)*sin(d)/cos(lat))+pi,2*pi)-pi
but I used the more general formula for long2:
B4X:
 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 ;
 

PD5DJ

Member
Licensed User
Longtime User
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:

derez

Expert
Licensed User
Longtime User
The method returns an array of the two required variables, here is an example:
B4X:
Sub Gnext_Click
Dim dbl() As Double
dbl = 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
 

PD5DJ

Member
Licensed User
Longtime User
The method returns an array of the two required variables, here is an example:
B4X:
Sub Gnext_Click
Dim dbl() As Double
dbl = 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

Aha! ok, im going to play with that tomorrow :)

I gues the lattitude and Longitude are in Decimal degrees? not DDMMSS?
 

nitinb4a

Member
Licensed User
Longtime User
Navigation tutorial an error

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:
 

nitinb4a

Member
Licensed User
Longtime User
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
 

nitinb4a

Member
Licensed User
Longtime User
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?

Pls. advise !

Thanks & regards
Nitin:sign0085:
 
Top