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

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

  • Geodesic.bas
    8.4 KB · Views: 1,219
Last edited:

laviniut

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

klaus

Expert
Licensed User
Longtime 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.
 

laviniut

Active Member
Licensed User
Longtime User
Yes, i see now. Thank you. I was in a hurry and i have not seen that.
 

arnold steger

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

Celso

Member
Licensed User
Longtime User
Hi, can you example how to convert ex:-19.868847,-43.965379 to UMC ?
 

jamesnz

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

DonManfred

Expert
Licensed User
Longtime User
Geodesic.bas appears to be a blank file ?
No, it is 8kb in size and has 260 lines...
Download it again

It is not a library btw, it is a class which you need to add to your app.
 
Top