Android Question Longitude & Latitude for my current location

eng.khalidvb

Member
Licensed User
Longtime User
Hi all,

I would like to developed an application android to get my longitude & latitude of my current location
I have saw many examples and using different libs , so I did one example but still I got an error.

here is my code:

in this code I got missing parameter !! could any once help me please. thanks in advance.

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
  Dim g As GPS
 
 

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim nav As Navigation
    Private lbl_info As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    If FirstTime  Then
        g.Initialize("GPS")
        
    End If
    
    
    
    
    Activity.LoadLayout("1")
 
 
End Sub


Sub GPS_LocationChanged (location1 As Location)
    
    lbl_info.Text = "Lat:" & location1.ConvertToSeconds(location1.Latitude) & "Long:" & location1.ConvertToSeconds(location1.Longitude)
    lbl_info.Text=& CRLF&"UTM:"&nav.LatLonToUTM(6378137.0,1/298.257223563,location1.Latitude,location1.Longitude)
    '= & CRLF & "UTM:" & nav.LatLonToUTM(6378137.0, 1/298.257223563, location1.Latitude, location1.Longitude)
    
    
    'lblLon.Text = "Lon = " & location1.ConvertToMinutes(location1.Longitude)

End Sub

Sub GPS_userenabled (Enabled As Boolean)
    
        
End Sub

Sub GPS_gpsstatus(satellites As List)
    
End Sub


Sub Activity_Resume

 If g.GPSEnabled = False Then
     ToastMessageShow("Please enable GPS",True)
    StartActivity(g.LocationSettingsIntent)
    Else
        g.Start(0, 0)
        
End If


End Sub

Sub Activity_Pause (UserClosed As Boolean)
g.Stop
End Sub
 

eng.khalidvb

Member
Licensed User
Longtime User
file uploaded for any assistance.

Here I got missing parameter :

B4X:
lbl_info.Text=& CRLF&"UTM:"&nav.LatLonToUTM(6378137.0,1/298.257223563,location1.Latitude,location1.Longitude)
 

Attachments

  • location.zip
    487.1 KB · Views: 510
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
lbl_info.Text=& CRLF ?
not
lbl_info.Text=lbl_info.Text & CRLF
 
Upvote 0

eng.khalidvb

Member
Licensed User
Longtime User

Erel - I tried this example but latitude & longitude not showing any values. I am connecting via WIFI but even it should show me the
latitude & longitude of my current location.

see picture . .
 

Attachments

  • Screenshot_2018-02-21-19-56-44.png
    Screenshot_2018-02-21-19-56-44.png
    75.4 KB · Views: 511
Upvote 0

eng.khalidvb

Member
Licensed User
Longtime User
Klaus - I am sorry but I did not get you. Is there any code line to be updated in my project ? If yes, what I should modify and how can I enable the satellite to be running behind my code to fixed the latitude & longitude of my current location. Your assistance appreciated.
 
Upvote 0

eng.khalidvb

Member
Licensed User
Longtime User
No I just only test it inside building. Is the make sense ?

Anyway I will try use it outdoor and will see the results.

Thanks for help. Appreaciated
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
As Klaus said the screenshot is good and shows the app is working fine. Go outside.. In the outside you also need to wait for about 1 or two minutes for the satellites to fix.
سلام.. فى الخارج تنتظر حوالى دقيقة حتى يتم اتصال التطبيق بالاقمار الصناعية
 
Upvote 0

eng.khalidvb

Member
Licensed User
Longtime User
Hi All,

I have did the same and it works perfect out building but my concern is the results of GPS coordinates as following :

this is my GPS app lot & lon results as shared in first post
it shows as DMS (Degree, Min, Seconds) which doesn't get correct location
Latitude :23:58.0264
Longitude:58:42.0313

I need latitude and longitude output similar to the following:
Latitude :23.580264
Longitude:58.420313

I am using the following website to get location as per the latitude and longitude inputs.
https://www.latlong.net/

see the snapshot attached.

any idea.
 

Attachments

  • lan_lon to address.PNG
    lan_lon to address.PNG
    8.9 KB · Views: 364
Upvote 0

eng.khalidvb

Member
Licensed User
Longtime User
Here is my latitude and longitude shows exact location as per the inputs.

find the attached snapshot
 

Attachments

  • Results.PNG
    Results.PNG
    463.1 KB · Views: 383
Upvote 0

klaus

Expert
Licensed User
Longtime User
The GPS returns lat and lon values as decimal degrees!
In Erels' project the lat / lon values are converted and displayed with minutes and seconds.
In this routine:
B4X:
Public Sub LocationChanged(Location1 As Location)
    lblLat.Text = "Lat = " & Location1.ConvertToMinutes(Location1.Latitude)
    lblLon.Text = "Lon = " & Location1.ConvertToMinutes(Location1.Longitude)
    lblSpeed.Text = $"Speed = $1.2{Location1.Speed} m/s "$
End Sub
Use simply:
B4X:
Public Sub LocationChanged(Location1 As Location)
    lblLat.Text = "Lat = " & Location1.Latitude
    lblLon.Text = "Lon = " & Location1.Longitude
    lblSpeed.Text = $"Speed = $1.2{Location1.Speed} m/s "$
End Sub
 
Upvote 0
Top