Android Question Showing coordinate

Izmirov.Yaminovich

Member
Licensed User
Longtime User
Hi,

I am trying to create something that can just show the google coordinate of the people that are holding the device. How do I write that? Let's say I have created two label to show longitude and latitude. What else should I include in the comments?

Thanks
 

DonManfred

Expert
Licensed User
Longtime User
Search for GPS tutorial
 
Upvote 0

Izmirov.Yaminovich

Member
Licensed User
Longtime User
I've tried to write up some according to the tutorial, but here's a problem. The app didn't show any coordinates.

It just shows:

Lat =
Lon =
Speed =
Satellites

without any numbers stating the coordinates. I'm pretty sure that I have turned on the location settings in my device.

Here's my log.
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private GPS1 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.

Private Label1 As Label
Private Label2 As Label
Private Label3 As Label
Private Label4 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:
'Activity.LoadLayout("Layout1")
If FirstTime Then
GPS1.Initialize("GPS")
End If
Activity.LoadLayout("GPS")
End Sub

Sub Activity_Resume
If GPS1.GPSEnabled = False Then
ToastMessageShow("Please enable the GPS device.",True)
StartActivity(GPS1.LocationSettingsIntent)
Else
GPS1.Start(0,0)
End If
End Sub

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

Sub GPS_LocationShanged (Location1 As Location)
Label1.Text = "Lat = " & Location1.ConvertToMinutes(Location1.Latitude)
Label2.Text = "Lon = " & Location1.ConvertToMinutes(Location1.Longitude)
Label3.Text = "Speed = " & Location1.Speed
End Sub

Sub GPS_UserEnabled (Enabled As Boolean)
ToastMessageShow("GPS device enabled = " & Enabled, True)
End Sub

Sub GPS_GpsStatus (Satellites As List)
Label4.Text = "Satellites" & CRLF
For i = 0 To Satellites.Size - 1
Private Satellite As GPSSatellite
Satellite = Satellites.Get(i)
Label4.Text = Label4.Text & CRLF & Satellite.Prn & _
" " & Satellite.Snr & " " & Satellite.UsedInFix & " " & Satellite.Azimuth _
& " " & Satellite.Elevation
Next
End Sub
 
Upvote 0

Izmirov.Yaminovich

Member
Licensed User
Longtime User
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private GPS1 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.

    Private Label1 As Label
    Private Label2 As Label
    Private Label3 As Label
    Private Label4 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:
    'Activity.LoadLayout("Layout1")
    If FirstTime Then
        GPS1.Initialize("GPS")
    End If
    Activity.LoadLayout("GPS")
End Sub

Sub Activity_Resume
    If GPS1.GPSEnabled = False Then
        ToastMessageShow("Please enable the GPS device.",True)
        StartActivity(GPS1.LocationSettingsIntent)
    Else
        GPS1.Start(0,0)
    End If
End Sub

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

Sub GPS_LocationShanged (Location1 As Location)
    Label1.Text = "Lat = " & Location1.ConvertToMinutes(Location1.Latitude)
    Label2.Text = "Lon = " & Location1.ConvertToMinutes(Location1.Longitude)
    Label3.Text = "Speed = " & Location1.Speed
End Sub

Sub GPS_UserEnabled (Enabled As Boolean)
    ToastMessageShow("GPS device enabled = " & Enabled, True)
End Sub

Sub GPS_GpsStatus (Satellites As List)
    Label4.Text = "Satellites" & CRLF
    For i = 0 To Satellites.Size - 1
        Private Satellite As GPSSatellite
        Satellite = Satellites.Get(i)
        Label4.Text = Label4.Text & CRLF & Satellite.Prn & _
            " " & Satellite.Snr & " " & Satellite.UsedInFix & " " & Satellite.Azimuth _
            & " " & Satellite.Elevation
    Next
End Sub
 

Attachments

  • GPS.zip
    24.6 KB · Views: 225
Upvote 0

klaus

Expert
Licensed User
Longtime User
I tested your program.
Changed the typo and it works.
If you test it inside, perhaps the device doesn't find satellites and you won't get anything.
I moved Private Satellite As GPSSatellite out of the For / Next loop.

Changed the layout for Label4, increased the Height and Vertical Alignment.
 

Attachments

  • GPS1.zip
    7.5 KB · Views: 244
Upvote 0

eurojam

Well-Known Member
Licensed User
Longtime User
same as Klaus, tested your program and it works, like Klaus said, leave your computer inside and go outside to test it...:)
 
Upvote 0
Top