Android Question [Solved] How to show coordinates from a service in a label in the main activity

asales

Expert
Licensed User
Longtime User
I have this code in a service, based in Background locate tracking, without notifications.
B4X:
Sub GPS_LocationChanged (Location1 As Location)
   If DateTime.Now > LastUpdateTime + 15 * DateTime.TicksPerSecond Then
       LastUpdateTime = DateTime.Now
       Log(gpm.isInside(Location1.Latitude,Location1.Longitude,True))
   End If
End Sub

I want to show the latitude and longitude in a label, that is on the main activity.

How I can do this?

Thanks in advance for any tip.
 

advansis

Active Member
Licensed User
Longtime User
Use CallSubDelayed2 statement.

1) Create a sub in your activity, ShowLocation
2) Inside your service: CallSubDelayed

In Main
B4X:
Sub ShowLocation (LC As Location)
    lblLocation.Text=LC.Latitude & " - " & LC.Longitude
End Sub

In service
B4X:
If SubExists(main,"ShowLocation") Then CallSubDelayed2(Main,"ShowLocation",Location1)

Hope this helps
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…