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

Discussion in 'Additional libraries, classes and official updates' started by Erel, Jul 2, 2013.

  1. Erel

    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:
    Code:
    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.
     

    Attached Files:

    Last edited: Jul 10, 2016
  2. laviniut

    laviniut Active Member Licensed User

    Sorry, how to convert GPS coordinates, like in GPS tutorial example from you, to decimal degrees ?
     
  3. klaus

    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:
    Code:
    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 !
    Code:
    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.
     
    Devan likes this.
  4. laviniut

    laviniut Active Member Licensed User

    Yes, i see now. Thank you. I was in a hurry and i have not seen that.
     
  5. arnold steger

    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?
     
  6. DaveW

    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.
     
    nimafallah, Devan and arnold steger like this.
  7. Celso

    Celso Member Licensed User

    Hi, can you example how to convert ex:-19.868847,-43.965379 to UMC ?
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    Code:
    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)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice