androidgoogle-mapsandroid-gpsoffline-modembtiles

Android Google Maps Offline - my location is not shown


I am trying to use Google Maps for Android, offline (always and forever). Surprisingly, I can't find any question here that asks or solves this issue specifically.

When I use a new offline phone, both my app and Google Maps show a blank map (dah, no map loaded) and 'my' location blue dot is not shown. Well, actually, no marker is shown.

To Reproduce

  1. Restore any Android phone to its factory settings
  2. Enable location services (GPS, without connecting to the internet at any stage)
  3. Open the Google Maps app

--> See that there is no 'my location' blue marker, although when you long click on the screen, the app shows its coordinates (meaning, GPS does work, but the map doesn't show it)

No my location symptom

Technical Symptoms

  1. Even when I load offline maps (.mbtiles format, custom ones, not Google's) they're still not shown (nor the markers). It's like Google put some code like this: if (no internet) hideAllViews(). Note that once I connect the phone to the internet, our custom tiles do work, even if I later turn the phone offline.

  2. I can interact with the map (long click to view the clicked location, for example, which shows that my GPS location indeed works), but that's about it (until I connect the phone to the internet, from which point I can turn it offline again but with everything surprisingly working).

Code Example - a simplified version

//build.gradle:
implementation 'com.google.android.gms:play-services-maps:17.0.0'

//MapActivity.kt
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.MapView
import com.google.android.gms.maps.MapsInitializer

class MapActivity : AppCompatActivity {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.map_activity)

        val mapFragment = supportFragmentManager.findFragmentByTag(MAP_FRAGMENT_TAG) as MapFragment?
            ?: MapFragment().also {
                supportFragmentManager.beginTransaction().add(R.id.map, it, MAP_FRAGMENT_TAG).commit()
            }

        mapFragment.getMapAsync(::onMapReady)
        mapFragment.retainInstance = true
    }

    private fun onMapReady(map: GoogleMap) {
        map.isMyLocationEnabled = true
        map.uiSettings.isMyLocationButtonEnabled = true

        Log.d("GoogleMap", "Map should be ready and visible with my-location marker shown, if phone's GPS is enabled")
    }
}

I hope someone here knows a trick or worked at Google and can shed some light on this.

Thank you!


Solution

  • It is not possible to load the API without connecting to the internet first since it was designed to be used online(As of now), so this is Working As Intended.

    Please note that using Maps SDK for android requires an internet connection first to load because it checks the API key. Then you can use the Map offline for a certain period of time(there's no definite period of time for offline functionality that requires you to be online again)

    But there are customers who are also interested in this functionality, so there is an ongoing entry for it in the Google Issue Tracker that was created since 2013 to let the API users be aware of this feature request.

    You can view and star the feature request here: https://issuetracker.google.com/35823181

    Please note that the Issue Tracker entry above is the authoritative source for public information regarding the aforementioned feature requests, and all publicly-relevant updates will be posted there.