B4A Library LocationManagerEx library

demo:
B4X:
'Activity module
 Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
 
 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 lmex As LocationManagerEx
    Dim btnGeoSet As Button
    Dim edthb As EditText
    Dim edtjd As EditText
    Dim edtwd As EditText
 End Sub
 
 Sub Activity_Create(FirstTime As Boolean)
 Activity.LoadLayout("1")
 lmex.Initialize("lm")
 End Sub
 Sub lm_locationchanged(locArg As Location)
    Log(locArg.altitude)'海拔
    Log(locArg.Longitude)'经度
    Log(locArg.Latitude)'纬度
 End Sub
 Sub Activity_Resume
 
 End Sub
 
 Sub Activity_Pause (UserClosed As Boolean)
 
 End Sub
 
 
 
 Sub btnGeoSet_Click
    Dim l As Location
    l.Initialize
    l.Altitude=edthb.Text
    l.Longitude=edtjd.Text
    l.Latitude=edtwd.Text
    lmex.GeoSet(l.Latitude,l.Longitude,l.Altitude)
 End Sub

outputlog
GeoSet:gpsLocation[mProvider=gps,mTime=0,mLatitude=111.0,mLongitude=111.0,mHasAltitude=true,mAltitude=55.0,mHasSpeed=false,mSpeed=0.0,mHasBearing=false,mBearing=0.0,mHasAccuracy=false,mAccuracy=0.0,mExtras=null]
;)
 

Attachments

  • gpsmock&lib.zip
    12.9 KB · Views: 870

warwound

Expert
Licensed User
Longtime User
Have you seen my xml2bb script?
It makes easy work of creating library documentation from a library's xml file:

Author: IceFairy333
Version: 1.1
  • Location
    Methods:
    • BearingTo (TargetLocation As Location) As Float
    • ConvertToMinutes (Coordinate As Double) As String
    • ConvertToSeconds (Coordinate As Double) As String
    • DistanceTo (TargetLocation As Location) As Float
    • Initialize
    • Initialize2 (Latitude As String, Longitude As String)
    • IsInitialized As Boolean
    Properties:
    • Accuracy As Float
    • AccuracyValid As Boolean [read only]
    • Altitude As Double
    • AltitudeValid As Boolean [read only]
    • Bearing As Float
    • BearingValid As Boolean [read only]
    • Latitude As Double
    • Longitude As Double
    • Speed As Float
    • SpeedValid As Boolean [read only]
    • Time As Long
  • LocationManagerEx
    Events:
    • locationchanged (locArg as Location As )
    • providerdisabled (providerStr as strin As )
    • providerenabled (providerStr as strin As )
    • statuschanged (providerStr as string As , statusflag as in As )
    Methods:
    • GeoSet (latitude As Double, longitude As Double, altitude As Double)
    • Initialize (EventName As String)
    • requestGPSLocation
    • requestMobileLocation
    • stopGPSListening
    • stopMobileListening
    Permissions:
    • android.permission.ACCESS_COARSE_LOCATION
    • android.permission.ACCESS_FINE_LOCATION
    • android.permission.ACCESS_MOCK_LOCATION
    • android.permission.INTERNET

I'll have a play with your library later.

Thanks.

Martin.
 
Last edited:

Dadeda

Member
Licensed User
Longtime User
how can i get the lat/long coordinates without using gps? only from wifi or 3g connection with your lib ?
 

3fazeac

Member
Licensed User
Longtime User
I used this LocationManagerEx library to get my app working on a tablet that does not have GPS or 3G (but does have bluetooth).

I feed the real GPS co-ordinates in from another phone using a GPS to bluetooth app and then pick up those co-ordinates on the tablet using a bluetooth to GPS app which displays the latitude and longitude just fine.

My app runs and gets the latitude and longitude from the _LocationChanged callback. So everything is fine

B4X:
Dim lmex As LocationManagerEx
lmex.Initialize("lm")
lmex.requestGPSLocation

Sub lm_locationchanged(Location1 As Location)
  Log("imported Lat " & Location1.Latitude)    ' this value supplied from other phone via the mock location mechanism
  Log("imported Long " & Location1.Longitude)
  Log("imported Alt " & Location1.Altitude)
End Sub

However, when I load the app on a device which supports GPS directly I want to use the standard GPS library and execute this code

B4X:
Dim GPS1 As GPS
GPS1.Initialize("GPS")
GPS1.Start(2000,0)

Sub GPS_LocationChanged(Location1 As Location)
  Log("GPS Lat " & Location1.Latitude)
  Log("GPS Long " & Location1.Longitude)
  Log("GPS Alt " & Location1.Altitude)
End Sub

but I get the following exception

java.lang.RuntimeException: java.lang.Exception: Sub gps_locationchanged signature does not match expected signature.
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:201)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
at anywheresoftware.b4a.gps.GPS$1.onLocationChanged(GPS.java:65)
at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:279)
at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:208)


It seems that the LocationManagerEx library has 'taken over' the message handlers even though no LocationManagerEx object is instantiated in the case where the GPS b4a library is used.

It there a way around this problem? Currently I have to have two completely separate executables, one for a device with real GPS support and another if I need to use the 'mock' location library.
 
Top