iOS Question Possible to release GPS handle?

laguilar

Member
Licensed User
Longtime User
I have an application that uses the current gps coordinates to do a search. When calling the App.OpenURL to open a comgooglemaps:// for directions, google maps application shows a waiting indicator, almost as if it appears its calculating the path, but will sit for as long as I let it (over 10 minutes at one point). I thought this may be related to my application not releasing the handle to the GPS. I've called the .Stop() on the LocationManager class, and even went as far as setting = Null on the reference to the LocationManager class. I've added a Sleep() in between the = Null and the call to App.OpenURL, all the same issue. I've confirmed it is the gps not releasing by attempting to call the App.OpenURL without initializing the LocationManager class and checking the location. Below is an example that should replicate the issue I am having (not tested, just pulled snippets from my main project to demonstrate). Any ideas? Thanks in advance.

B4X:
'Code module
#Region  Project Attributes
    #ApplicationLabel: B4i Example
    #Version: 1.0.0
    'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
    #iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
    #iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
    #Target: iPhone, iPad
    #ATSEnabled: True
    #MinVersion: 8
    
    #PlistExtra:<key>NSLocationWhenInUseUsageDescription</key><string>Your location is used during search.</string>
    #PlistExtra:<key>NSLocationUsageDescription</key><string>Your location is used during search.</string>
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
    Private xui As XUI
    Private loc As LocationManager
End Sub

Private Sub Application_Active
    Dim lm As LocationManager
    loc = lm
    loc.Initialize("loc")
End Sub

Private Sub Application_Background
    loc = Null
End Sub

Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.RootPanel.LoadLayout("Page1")
    NavControl.ShowPage(Page1)
    loc.Initialize("loc")
End Sub

Sub Step1
    ' Find our location
    loc.Start(0)
End Sub

Sub loc_LocationChanged(NewLocation As Location)
    ' Got our GPS coordinates, now lets stop gps and save battery
    loc.Stop
    '' Do some search using the coordinates we got
End Sub

Sub Step2
    loc.Stop ' Make sure gps is stopped
    loc = Null ' lets try to destroy the LocationManager handle
    Sleep(100) ' give the app a moment to maybe allow the gps to release?
    
    '' In our search result we found something we like, lets navigate to it! (New York, NY in this case)
    If App.CanOpenURL("comgooglemaps://?daddr=40.6976637,-74.119764") = True Then ' lets see if google maps app is installed (preferred)
        App.OpenURL("comgooglemaps://?daddr=40.6976637,-74.119764") ' yes, lets show google maps
    Else
        App.OpenURL("http://maps.apple.com/?daddr=40.6976637,-74.119764") ' no google maps, lets load apple's default maps app
    End If
End Sub

Private Sub Page1_Resize(Width As Int, Height As Int)
    
End Sub
 

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
Upvote 0
Top