B4A Library [B4X] [class] Geodesic - Convert Lat Lon / UTM coordinates

Erel

Administrator
Staff member
Licensed User
The attached class allows you to convert coordinates between Lat Lon coordinates and UTM coordinates.

The conversion is done with WGS84 datum. Note that the class code can handle other datums as well.

Usage example:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim g As Geodesic
   g.Initialize
   Dim u As UTM
   u.UtmXZone = 36
   u.X = 500000
   u.Y = 3600000
   u.NorthHemisphere = True
   Dim ll As LatLon
   ll = g.WGS84UTMTOLatLon(u)
   Log(ll.Lat & "N " & ll.Lon & "E")
End Sub
There were reports of inaccurate results. I wasn't able to reproduce them. Make sure to test it thoroughly.
 

Attachments

Last edited:

laviniut

Active Member
Licensed User
Sorry, how to convert GPS coordinates, like in GPS tutorial example from you, to decimal degrees ?
 

klaus

Expert
Licensed User
The GPS library returns decimal degrees !
If you look in the code of the GPSTutorial project you would see in the GPS_LocationChanged routine that the original location values are converted to minutes !
.
Replace this routine:
B4X:
Sub GPS_LocationChanged (Location1 As Location)
    lblLat.Text = "Lat = " & Location1.ConvertToMinutes(Location1.Latitude)
    lblLon.Text = "Lon = " & Location1.ConvertToMinutes(Location1.Longitude)
    lblSpeed.Text = "Speed = " & Location1.Speed
End Sub
by this one !
B4X:
Sub GPS_LocationChanged (Location1 As Location)
    lblLat.Text = "Lat = " & Location1.Latitude
    lblLon.Text = "Lon = " & Location1.Longitude
    lblSpeed.Text = "Speed = " & Location1.Speed
End Sub
You could use NumberFormat to format the output.
 

arnold steger

Member
Licensed User
i have a big database whit utm coordinates without utmxzone.
example point from database: 733149.983999997 5183855.2929
i want convert in lat/lon.
how can find the u.UtmXZone for each point?
 

DaveW

Active Member
Licensed User
You can't. There are 60 zones covering the earth, every one of which will have a valid position 733149.983999997 5183855.2929 - or any other X & Y combination. Assuming these are in Northing Easting order then each zone will have a point with these coordinates about 460Km East or West of the adjacent zone.
 

Erel

Administrator
Staff member
Licensed User
B4X:
Dim geo As Geodesic
geo.Initialize
Dim ll As LatLon
ll.Lat = -19.868847
ll.Lon = -43.965379
Dim utm As UTM = geo.WGS84LatLonToUTM(ll)
Log(utm)
 

jamesnz

Active Member
Licensed User
where is the geodesic Library?
has it been removed , or incorporated elsewhere ?
Geodesic.bas appears to be a blank file ?
 
Top