Android Question [SOLVED] GoogleMaps Without PERMISSION_ACCESS_FINE_LOCATION

mmieher

Active Member
Licensed User
Longtime User
GoogleMap thing still unsolved but it is not Permissions.
---------------------------------------------------------------

As near as I can tell, through trial-and-error slogging, none of the map API stuff works without pleading for PERMISSION_ACCESS_FINE_LOCATION.

It is unusual for me to want something a little odd, but I want to use GoogleMaps "everything", but I do not care about the device's location. I especially do not want to ask the user's permission for anything whatsoever (after PlayStore Install button).

I want to pump a latitude and longitude to gMaps, then let the Goog do its thing. (no WebView stuff please)

I have used this example many times in the past:
https://www.b4x.com/android/forum/threads/b4x-b4xpages-googlemaps-example.120121/#content

Without permission, app blows up at "Wait For gMap_Ready"
Code:
Private Sub InitializeMap As ResumableSub
    LogSub("InitializeMap")
    #if B4J
    gmap.Initialize2("gmap", Null, Main.API_KEY)
    pnlMap.AddView(gmap.AsPane, 0, 0, pnlMap.Width, pnlMap.Height)
    Wait For gmap_Ready
    Return gmap.IsReady
    #Else If B4i
    gmap.Initialize("gmap", Main.API_KEY)
    pnlMap.AddView(gmap, 0, 0, pnlMap.Width, pnlMap.Height)
    gmap.GetUiSettings.CompassEnabled = True
    gmap.GetUiSettings.MyLocationButtonEnabled = True
    gmap.MyLocationEnabled = True
    Return True
    #Else if B4A
       
    Wait For gMap_Ready
    gMap = gMapFragment.GetMap
    If gMap.IsInitialized Then
        ''        Log("gmap.IsInitialized")
        gMap.MyLocationEnabled = True
    End If
    Return gMap.IsInitialized
    #End If
End Sub

Snippet from log (broke App again for you guys):
Code:
B4Silly 08:02:27:528 DisplayGMap: 45.53122329711914 / -122.68580627441406
mGMap 08:02:27 Initialize: mgmap1
mGMap 08:02:27 DesignerCreateView
mGMap 08:02:27 DisplayGMap: 45.53122329711914 / -122.68580627441406
mGMap 08:02:27 InitializeMap
java.lang.IllegalArgumentException: No view found for id 0x2711 (unknown) for fragment MapFragment{77168fa #0 id=0x2711}
    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1297)
    at android.app.FragmentManagerImpl.addAddedFragments(FragmentManager.java:2431)
    at android.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2210)
    at android.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2166)
    at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2067)
    at android.app.FragmentManagerImpl$1.run(FragmentManager.java:742)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:223)
    at android.app.ActivityThread.main(ActivityThread.java:7656)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

Some MapFragment is pissed. No idea what anything else means.
 
Last edited:
Solution
"Make a new small project ..."

Some of the usual cut/paste and Add Existing Module errors.

However, my take-away here is, do not mess with Restricting API Keys until you know everything else works. GoogleMaps example not published, so no nasty message about the exposed key.
I don't understand. The example project works for you?
The permission is only requested after the Wait For line.
The example works great.

My project worked one time. Right when I did a "quickie" permission thing in Activity_Create (not somewhere I should in B4XPages). Must have been a fluke? When I do the permissions correctly, I get back to where I started with the MapFragment missing view error.

I initially copied the layout with the MapFragment (gMap) from another WORKING project. I have now recreated the layout from scratch. Still the error on Wait For gMap_Ready. I have been comparing everything regarding this on the two projects, starting with Manifest.

I have a log statement that says the App has the fine location permission before I try to display a map.

Especially since I caught your attention (maybe), I am going to make a "small project". That process will probably lead to the answer. I will post whatever happened. Thank you, Erel.
 
Last edited:
Upvote 0
"Make a new small project ..."

Some of the usual cut/paste and Add Existing Module errors.

However, my take-away here is, do not mess with Restricting API Keys until you know everything else works. GoogleMaps example not published, so no nasty message about the exposed key.
 
Upvote 0
Solution
Back
Top