Hello,
I am trying to implement google map. But after running the map for 3 to 5 minutes it is crashing. Also no log is showing at the window.
I have tried to implement @Erel below code still no luck..
Code from Map Activity
Code from Starter.bas
Please suggest....
I am trying to implement google map. But after running the map for 3 to 5 minutes it is crashing. Also no log is showing at the window.
I have tried to implement @Erel below code still no luck..
B4X:
If File.Exist(File.DirInternal, "google_bug") = False Then
File.Delete(File.DirInternal, "ZoomTables.data")
File.WriteString(File.DirInternal, "google_bug", "")
End If
Code from Map Activity
B4X:
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
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.
Private gmap As GoogleMap
Private MapFragment1 As MapFragment
Private rp As RuntimePermissions
Private StateMessage As String
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("1")
If File.Exists(File.DirInternal, "google_bug") = False Then
File.Delete(File.DirInternal, "ZoomTables.data")
File.WriteString(File.DirInternal, "google_bug", "")
End If
Wait For MapFragment1_Ready
gmap = MapFragment1.GetMap
rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result Then
Log(Tracker.gpslat)
Log(Tracker.gpslong)
gmap.MyLocationEnabled = True
gmap.TrafficEnabled=True
'gmap.MyLocation.Initialize(Tracker.gpslat,Tracker.gpslong)
Do While gmap.MyLocation.IsInitialized = False
Log("Location not initialized... Sleep a while...")
Sleep(250)
Loop
If gmap.MyLocation.IsInitialized Then
Dim CameraPosition1 As CameraPosition 'CameraPosition1.Initialize2(gmap.MyLocation.Latitude, gmap.MyLocation.Longitude, gmap.CameraPosition.Zoom, 0, 0)
gmap.MapType=gmap.MAP_TYPE_NORMAL
CameraPosition1.Initialize(gmap.MyLocation.Latitude,gmap.MyLocation.Longitude, 16)
gmap.AnimateCamera(CameraPosition1)
Sleep(2000)
CameraPosition1.Initialize(gmap.MyLocation.Latitude,gmap.MyLocation.Longitude, 18)
gmap.AnimateCamera(CameraPosition1)
'Dim m As Marker
'Dim bitmap As Bitmap
'bitmap= LoadBitmapResize(File.DirAssets,"small-axe.png",30dip,30dip,True)
'gmap.AddMarker3(gmap.MyLocation.Latitude,gmap.MyLocation.Longitude,"",LoadBitmapResize(File.DirAssets,"small-axe.png",30dip,30dip,True))
End If
Else
Log("No permission!")
End If
End Sub
Sub Activity_Resume
Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result Then
StartService(Tracker)
Else
ToastMessageShow("No permission...", True)
End If
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Update_Location(newloc As Location)
If newloc.IsInitialized Then
Dim CameraPosition1 As CameraPosition 'CameraPosition1.Initialize2(gmap.MyLocation.Latitude, gmap.MyLocation.Longitude, gmap.CameraPosition.Zoom, 0, 0)
CameraPosition1.Initialize(newloc.Latitude,newloc.Longitude, 17)
gmap.moveCamera(CameraPosition1)
End If
End Sub
Sub MapFragment1_Click (Point As LatLng)
rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Starter.flp.IsConnected = False Then
SetState("Location provider not available")
End If
If Result Then
Dim rs As ResumableSub = CallSub(Starter, "CheckLocationSettingStatus")
Wait For (rs) Complete (SettingsResult As LocationSettingsResult)
Dim sc As StatusCodes
Select SettingsResult.GetLocationSettingsStatus.GetStatusCode
Case sc.SUCCESS
SettingsAreGood
Case sc.RESOLUTION_REQUIRED
SetState("RESOLUTION_REQUIRED")
SettingsResult.GetLocationSettingsStatus.StartResolutionDialog("srd")
Wait For srd_ResolutionDialogDismissed(LocationSettingsUpdated As Boolean)
If LocationSettingsUpdated Then
SettingsAreGood
Else
SetState("Not enabled")
End If
Case Else
SetState("Not available")
End Select
Else
SetState("No permission")
End If
End Sub
Sub SettingsAreGood
SetState("Location enabled - waiting for updates")
CallSub(Starter, "StartLocationUpdates")
End Sub
Public Sub Location_Changed (loc As Location)
'lblLocation.Text = $"$1.2{loc.Latitude} / $1.2{loc.Longitude}"$
End Sub
Sub SetState (msg As String)
StateMessage = msg
'lblState.Text = "State: " & msg
'Log(lblState.Text)
End Sub
Code from Starter.bas
B4X:
#Region Service Attributes
#StartAtBoot: False
#ExcludeFromLibrary: True
#End Region
Sub Process_Globals
Public rp As RuntimePermissions
Public flp As FusedLocationProvider
' Dim sql As SQL
End Sub
Sub Service_Create
flp.Initialize("flp")
flp.Connect
'If File.Exists(File.DirInternal,"sql2")=False Then
' File.Copy(File.DirAssets,"ambulance.db",File.DirInternal,"sql2")
'End If
'
' sql.Initialize(File.DirInternal,"sql2",True)
End Sub
Sub flp_ConnectionSuccess
Log("Connected to location provider")
End Sub
Sub flp_ConnectionFailed(ConnectionResult1 As Int)
Log("Failed to connect to location provider")
End Sub
Sub Service_Start (StartingIntent As Intent)
Service.StopAutomaticForeground
End Sub
Sub Service_TaskRemoved
'This event will be raised when the user removes the app from the recent apps list.
End Sub
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub CheckLocationSettingStatus As ResumableSub
Dim f As LocationSettingsRequestBuilder
f.Initialize
f.AddLocationRequest(CreateLocationRequest)
flp.CheckLocationSettings(f.Build)
Wait For flp_LocationSettingsChecked(LocationSettingsResult1 As LocationSettingsResult)
Return LocationSettingsResult1
End Sub
Public Sub StartLocationUpdates
flp.RequestLocationUpdates(CreateLocationRequest)
End Sub
Private Sub flp_LocationChanged (Location1 As Location)
CallSub2(map, "Location_Changed", Location1)
End Sub
Sub Service_Destroy
End Sub
Private Sub CreateLocationRequest As LocationRequest
Dim lr As LocationRequest
lr.Initialize
lr.SetInterval(0)
Return lr
End Sub
Please suggest....