LocationManager Library

XverhelstX

Well-Known Member
Licensed User
Longtime User
LocationManager updated to 1.1!

A small update with some new features.
Some methods have been changed.
You can now easily retrieve your coordinates from your gps without the need of the GPS library.
I got my latitude, longitude, altitude, etc in less than 15 seconds.

Tomas
 

bluedude

Well-Known Member
Licensed User
Longtime User
Location change event

One question,

Is the Location Change event identical to the GPS one? I mean, is this event updated when you move (like GPS) or do you always need to update it manually?

Cheers,
 

bluedude

Well-Known Member
Licensed User
Longtime User
How to use in combination with GPS

Hi,

Is the Location_LocationChanged an event in case of GPS or CellID?

So if I change location physically does it call Location_LocationChanged?

And how does this work together with my normal GPS service? I use a background service to track with GPS.

Please some answers.
 

corwin42

Expert
Licensed User
Longtime User
Hi Tomas,

this library is missing on the wiki page with the additional libraries.

Another thing is that in your libraries (at least this one and PhoneStateListener too) you don't add the @Events annotation to your source. Look at Erels post how this should be done.

If you add the @Events annotation to your libraries it would be possible to use autocompletion for event subs in the IDE.

Edit: Just one more thing. This library adds android.permission.INTERNET. Is this really necessary. I don't think so.
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
Just for ref: very needed a static status value, like GPSListening, MobileListening as boolean...
And status of the system mobile navigation permission.
 

boten

Active Member
Licensed User
Longtime User
Is it possible to requestMobileLocation when Packet Data is DISABLED? (when GPS is OFF)
 

reijndert

Member
Licensed User
Longtime User
I created a program with the library and it works fine.
But what if there is only Wifi and no GPS or Cell functionality on a tablet?

Is there a time-out or how do i check if the locationmanager will return a location? Now it is waiting forever ...
 

Firpas

Active Member
Licensed User
Longtime User
What is the diferentent beetwen LocationManager v 1.0 and v 1.1?

Thanks for your cooperation
 

Air

Member
Licensed User
Longtime User
Can´t stop Location-Listener

How can i stop the MobileListening?

In my App i have a Preference Value FindCell as Boolean.

In Activity_Resume i Check this Boolean.

B4X:
Sub Activity_Resume
   Prefs_HandleSettings

   Location.requestMobileLocation

   If prefsmanager.GetBoolean("FindCell") = False Then
      Location.stopMobileListening
   End If
End Sub

If i set this Value to False in Prefs-Screen and go back to Main-Activity, the Location-Listener is still looking for my location, It does not stop. Because, i the the Toastmessage again and again and again...

If i Exit my App and start it again with the Last Setting of FindCell (to False)
The Listener ist stopped.

How can I stop the listener without terminating my app?
 

Air

Member
Licensed User
Longtime User
slept one night on it and my problem is solved

Now i use the following code in Activity-Create / Activity-Resume

B4X:
Sub Activity_Create(FirstTime As Boolean)
   Location.Initialize("Location")
   Location.requestMobileLocation 'normally this entry is only in Activity_Resume
End Sub

Sub Activity_Resume
   Prefs_HandleSettings
   If prefsmanager.GetBoolean("FindCell") = False Then
      Location.stopMobileListening
   Else
      Location.requestMobileLocation
   End If
End Sub

This works perfect for me.
 

Catom

Member
Licensed User
Longtime User
Hi,

I've a problem, I tried your example and the only thing I can do is selecting "Update Location" or "Stop Listening" from the menu.

When I choose "Update Location" the GPS begins to do its job, but it stays there, never returns anything, I'm trapped at the black screen.

BUT, I'm not moving, I'm expecting it returns something like the GPS programs I've installed (Like Waze) which shows a Map with the point where I'm at (I never turn off hardware GPS)

Can anyone help me?
Thanks a lot!

James
 

Air

Member
Licensed User
Longtime User
I hope i understand you right.

I found out, that the locationmanager looks ca. every 30 seconds for a new location.

if you want to store your location, you have to save it in a variable.
I do this in the Sub Location_LocationChanged

This library doesn´t do anything other. it only found your location.
if you want to show your location in google-maps or something, you have to write another sub´s or build activity´s to do that.

I hope you understand what i mean.

e.g. Variable FinCell is now prefs_gps_on

B4X:
Sub Location_LocationChanged (Longitude As Double, Latitude As Double, Altitude As Double, Accuracy As Float, Bearing As Float, Provider As String, Speed As Float, Time As Long) 
'   ToastMessageShow("Lat: " & Latitude & " - Long: " & Longitude, True)

   If prefsmanager.GetBoolean("prefs_gps_on") = True Then
      gps1_img.Bitmap = LoadBitmap(File.DirAssets,"gps_found.png")
      DoEvents
      If prefsmanager.GetBoolean("prefs_gps_snd") = True Then
         Play_Beep("gps_found", 6)
      End If
      prefsmanager.SetString("prefs_gps_pos", Latitude & "," & Longitude)
      gps1_img.Bitmap = LoadBitmap(File.DirAssets,"gps_on.png")
   End If

End Sub

In this Sub, the Location.stopMobileListening doesn´t really terminate the Locationmanager, it only stops for searching.
But it doesn´t store my location in my preferences.

B4X:
Sub Activity_Resume
   Prefs_HandleSettings
   If prefsmanager.GetBoolean("prefs_gps_on") = False Then
      Location.stopMobileListening
      prefsmanager.SetString("prefs_gps_pos", "0,0")
   Else
      Location.requestMobileLocation 
   End If
End Sub

That´s enough for me, because i build a html-file with the location-coordinates and send it to my ftp-server.

And if i dont want, that anyone can look my location, i can disable this function in my preferences.
 
Last edited:

Catom

Member
Licensed User
Longtime User
Hi! Thanks for your answer, but I think I didn't explain fine myself :) And I didn't understand the problem correctly.

At first I thought it was not working because I didn't receive any data and I also thought it could be because I was inside my room and not moving (meaning, no new location)

But today I did some testings, and it seems my room is made of lead or something, GPS data can't be received.

So, now my problem is... Can I get the last GPS position where the phone was?

Mmmm... Now I know I can save last position, but is there any way to know it even before the user run my app for the first time?

Thanks a lot :)
 
Last edited:

lagore

Active Member
Licensed User
Longtime User
Hi Catom,
I am in the process of creating a modified version of this library, it will add another function that uses the 'getLastKnownLocation' from all available providers (gps, network & passive) and returns their position, time & accuracy. I have this portion working. I am also trying to add a function whereby you will be notified when you are within range of a given location via pendingIntent.
 

Air

Member
Licensed User
Longtime User
Hy lagore,

is there a chance to add an option that can really terminate the locationlistener?
Something like location.close ?
 

lagore

Active Member
Licensed User
Longtime User
Hi Air,
I think the problem with stopping LocationListener is in your code, if you have already started the LocationListener then there is no need to start it again in Activity_Resume as this stacks up another listener so that when you StopListener it only stops one of them. If you run the sample app in post #1 start the mobileListener put you app into the background wait a moment then relaunch the app you will still get the mobile position updates, select stopListener and you will not get anymore updates. You may have to use some sort of indicator in Activity_Create using if Firsttime.
 

netchicken

Active Member
Licensed User
Longtime User
I am getting "Location Disabled" as my response, is that because I am on an XT network?
 

jmon

Well-Known Member
Licensed User
Longtime User
I'm getting an error (on b4a 2.71) when I click on "Stop Listening":

B4X:
LocationManager has been initialized.
** Activity (main) Resume **
LocationManager1stopGPSListening (B4A line: 45)
lm.stopGPSListening
java.lang.IllegalArgumentException: listener==null
   at android.location.LocationManager.removeUpdates(LocationManager.java:804)
   at com.rootsoft.locationmanager.LocationManager1.stopGPSListening(LocationManager1.java:141)
   at com.rootsoft.locationmanager.main._mnustoplistening_click(main.java:445)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:521)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
   at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
   at com.rootsoft.locationmanager.main$B4AMenuItemsClickListener.onMenuItemClick(main.java:142)
   at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
   at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
   at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:545)
   at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
   at android.view.View$PerformClick.run(View.java:8817)
   at android.os.Handler.handleCallback(Handler.java:587)
   at android.os.Handler.dispatchMessage(Handler.java:92)
   at android.os.Looper.loop(Looper.java:144)
   at android.app.ActivityThread.main(ActivityThread.java:4937)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:521)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
   at dalvik.system.NativeStart.main(Native Method)
java.lang.IllegalArgumentException: listener==null


I am also not getting any position update, just the Msgbox("Provider","Provider Disabled") showing. I am using an HTC desire Android 2.2.

What am I doing wrong? I just ran the example
 
Top