Please help me indicate "My location" on Google Maps.
See the GoogleMaps Tutorial.Please help me indicate "My location" on Google Maps.
Here's my codeSee the GoogleMaps Tutorial.
Sub Process_Globals
Private rp As RuntimePermissions
End Sub
Sub Globals
Private gmap As GoogleMap, frag As MapFragment, marc As Marker, pos As CameraPosition
Dim CenterLat, CenterLong As Float
Dim pnlAB As Panel
Dim Title As Label
Dim Menu As ImageView
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("gmap")
Menu.Visible=False
End Sub
Sub ShowMap(coordinates() As Float, name As String)
Title.Text=name
Title.TextSize=Starter.TextSize
CenterLat=coordinates(0)
CenterLong=coordinates(1)
If frag.IsGooglePlayServicesAvailable = False Then Return
' For Each permission As String In Array(rp.PERMISSION_ACCESS_FINE_LOCATION)
' rp.CheckAndRequest(permission)
' Wait For Activity_PermissionResult (permission As String, Result As Boolean)
' If Result = False Then
' ToastMessageShow("No permission!", True)
' Activity.Finish
' Return
' Else
' gmap.MyLocationEnabled=True
' End If
' Next
End Sub
Sub frag_Ready
gmap = frag.GetMap
pos.Initialize(CenterLat, CenterLong, 10)
gmap.MoveCamera(pos)
If marc.IsInitialized Then marc.Remove
marc = gmap.AddMarker2(pos.Target.Latitude, pos.Target.Longitude, Activity.Title, gmap.HUE_GREEN)
End Sub
Corrected the codeIf you uncomment part of the code, an error occurs.
Sub frag_Ready
gmap = frag.GetMap
pos.Initialize(CenterLat, CenterLong, 10)
gmap.MoveCamera(pos)
If marc.IsInitialized Then marc.Remove
marc = gmap.AddMarker2(pos.Target.Latitude, pos.Target.Longitude, Activity.Title, gmap.HUE_GREEN)
For Each permission As String In Array(rp.PERMISSION_ACCESS_FINE_LOCATION)
rp.CheckAndRequest(permission)
Wait For Activity_PermissionResult (permission As String, Result As Boolean)
If Result = False Then
ToastMessageShow("No permission!", True)
Activity.Finish
Return
Else
gmap.MyLocationEnabled=True
End If
Next
End Sub
private sub timer_tick
private myLoc as Latlng = gmap.myLocation
if (myLoc <> Null) then
if (theMarker <> null) then
theMarker.remove
end if
theMarker = gmap.addMarker3(myLoc.latitude,myLoc.Longitude,"You are here",LoadBitmap(File.dirassets,"mypng.png")
end if
Sub frag_Ready
gmap = frag.GetMap
pos.Initialize(CenterLat, CenterLong, 10)
gmap.MoveCamera(pos)
If marc.IsInitialized Then marc.Remove
marc = gmap.AddMarker2(pos.Target.Latitude, pos.Target.Longitude, Title, gmap.HUE_GREEN)
For Each permission As String In Array(rp.PERMISSION_ACCESS_FINE_LOCATION)
rp.CheckAndRequest(permission)
Wait For Activity_PermissionResult (permission As String, Result As Boolean)
If Result = False Then
ToastMessageShow("No permission!", True)
Activity.Finish
Return
Else
gmap.MyLocationEnabled=True
Sleep(3000)
Log(gmap.myLocation.Latitude)
End If
Next
End Sub
I’m checking one resolution, because that’s how it was in the example. I check the other ones I need in the main module B4A. ThisIt is not clear why you would want to loop over only 1 permission
For Each permission As String In Array(rp.PERMISSION_READ_CONTACTS, rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
rp.CheckAndRequest(permission)
Wait For Activity_PermissionResult (permission As String, Result As Boolean)
If Result = False Then
Activity.Finish
Return
End If
Next
Error:What was the error?
mainmenu_setdata (java line: 722)
java.lang.NullPointerException: Attempt to invoke virtual method 'int anywheresoftware.b4a.objects.collections.Map.getSize()' on a null object reference
at sv.bystrovzorov.mainmenu._setdata(mainmenu.java:722)
at sv.bystrovzorov.mainmenu._activity_resume(mainmenu.java:486)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at sv.bystrovzorov.mainmenu.afterFirstLayout(mainmenu.java:111)
at sv.bystrovzorov.mainmenu.access$000(mainmenu.java:17)
at sv.bystrovzorov.mainmenu$WaitForLayout.run(mainmenu.java:83)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:230)
at android.os.Looper.loop(Looper.java:319)
at android.app.ActivityThread.main(ActivityThread.java:8919)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
*** Service (starter) Create ***
Using FileProvider? true
** Service (starter) Start **
** Activity (main) Create (first time) **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (loader) Create (first time) **
** Activity (loader) Resume **
** Activity (loader) Pause, UserClosed = false **
Sleep not resumed (context is paused): sv.bystrovzorov.circularprogressbar$ResumableSub_AnimateValueTo
** Activity (mainmenu) Create (first time) **
** Activity (mainmenu) Resume **
AddApplicationText(
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
)
This is in the main program, I just carelessly transferred it to the example.You manifest is missing the following lines
For the same reasonNot sure why you are adding all those permissions in the Manifest, this is unnecessary also.
Никогда не использовал его раньше. Подскажите пожалуйста, как это сделать правильно.Add a timer, and check MyLocation in the timer