Android Question Toast latitude and longitude ?

Devv

Active Member
Licensed User
Longtime User
Hi all
i has been trying for 2 days to make a simple app that toast's the latitude and longitude of my current location

i had seen MR.Erel's GPS Tut and other tuts but i never succeeded in making my simple app

any one can give me the full code ? i don't want any gui of labels or buttons just a simple toast of current location

thanks in advanced
 

Mark Read

Well-Known Member
Licensed User
Longtime User
The following should help, not tested. Assuming you have a gps and it is turned on!

B4X:
Sub Globals
  Dim gps1 As GPS
end sub

Sub Activity_Create(FirstTime As Boolean)
  If FirstTime Then
     gps1.Initialize("GPS")
     End If
end sub

Sub GPS_LocationChanged (Location1 As Location)

  ToastMessageShow("Lon,Lat:"& Location1.Latitude & "," & Location1.Longitude,True)
  gps1.Stop

end sub
 
Upvote 0

Devv

Active Member
Licensed User
Longtime User
it didnt worked for me i had not got any toasts may you please test it on you device ?
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
I assume that you have gps enabled, you are outdoors and you have waited a while for the location to be found?

Sorry, my fault.

please add after the end if in activity_create:

B4X:
gps1.Start(0, 0) 'Listen to GPS with no filters.

Of course it won't work if we don't start the gps!
 
Upvote 0

Devv

Active Member
Licensed User
Longtime User
still not working for me ... i have gps enabled , i get the gps circle when i run the app , but the circle is always empty , and i never got the toast

may you test it ?
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
Hi,
Just now I tested your app AS IS and without changing anything, and it is working perfectly.
 
Upvote 0

Devv

Active Member
Licensed User
Longtime User
Hi,
Just now I tested your app AS IS and without changing anything, and it is working perfectly.

thanks for testing it , you got a toast with the location , what about the gps icon ??
 
Upvote 0

Devv

Active Member
Licensed User
Longtime User
when i run my app i only get this gps icon
it wont be like this
and i never get the location.
i had just tried my gps on google maps it is working fine
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
This code works:
B4X:
Sub Process_Globals
    Dim gps1 As GPS
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        gps1.Initialize("GPS")
    End If
End Sub

Sub Activity_Resume
    If gps1.GPSEnabled = False Then
        ToastMessageShow("Please enable the GPS device.", True)
        StartActivity(gps1.LocationSettingsIntent) 'Will open the relevant settings screen.
    End If
    gps1.Start(0, 0) 'Listen to GPS with no filters.

End Sub

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

Sub GPS_LocationChanged (Location1 As Location)
    Activity.Title = "Lon,Lat:"& Location1.Latitude & "," & Location1.Longitude
'    ToastMessageShow("Lon,Lat:"& Location1.Latitude & "," & Location1.Longitude, False)
End Sub
 

Attachments

  • gps.zip
    5.9 KB · Views: 155
Upvote 0

Devv

Active Member
Licensed User
Longtime User
i tried the code on another device it worked !, seems the problem is with my device but google maps is working fine with my arc s custom rom
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
restart the device and try again.. this will stop any app that may be leaving something in the memory or even running in the background. when starts
don't run google maps.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…