0

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!

  • As opposed to most similar questions, I do know how to make this work (internet...) but am asking specifically about a use case where a new phone can never be connected to the internet - not even one time for one second.

  • I am familiar with other offline maps services, but am trying to solve this with Google's maps, at least for now

guy_m
  • 3,110
  • 2
  • 19
  • 33
  • 2
    Please provide a [mcve] (your code) that allows to reproduce the issue. – MrUpsidown Nov 07 '22 at 13:09
  • Hi @MrUpsidown, thx for the help. I'm not sure what example to provide, because I'm asking about the very basic GoogleMaps functionality. For example, the Google Maps app itself works this same way (no 'my location' marker on a blank map, when using a new offline phone). I'll edit the question to clarify this – guy_m Nov 07 '22 at 15:38
  • My comment was sort of sarcastic... Is your question about **using** the Google Maps app? Or are you asking about an app that you have developed? If there is no code (of yours) involved, then you'd better be asking on https://superuser.com/ as your question would be off-topic here (not about programming). – MrUpsidown Nov 07 '22 at 19:22
  • I added some code as per your suggestion. Hope it helps. – guy_m Nov 08 '22 at 10:05
  • 1
    Doing a very quick research on the subject I found many Q/A here stating that caching the Google Maps tiles goes against their TOS. If you are using your own tiles (tile server) then it seems feasible. – MrUpsidown Nov 08 '22 at 10:09
  • Thanks. Yes, we use our own tiles. We cannot use Google's because we cannot have internet connection at any stage. When I load our custom tiles and the internet is on, everything works well (even if I later turn it off). But if I load them on a 'new', offline phone, nothing shows, like in the picture above. Any idea? – guy_m Nov 08 '22 at 10:48
  • @MrUpsidown you shared that it seems feasible, care sharing your thoughts please? thx :) – guy_m Nov 10 '22 at 09:44
  • How about [this solution](https://stackoverflow.com/a/57339898/1238965)? – MrUpsidown Nov 10 '22 at 09:59
  • This solution (like many others I've found) still requires the app to go online (for caching the 'offline' tiles). But in my case, I can never go online. And according to my tests (this is exactly my question) - if the app never goes online, the map will not work, even if I load tiles from a usb. It's like Google Maps API (Play Services) requires the phone to go online, at least one time. – guy_m Nov 10 '22 at 10:09

1 Answers1

1

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.

Yrll
  • 1,619
  • 2
  • 5
  • 19
  • This is great, thank you! Do you know if there's any official documentation stating what you just said, beside the issue tracker? I'd like to record that on my company's docs. Thx again! – guy_m Nov 12 '22 at 16:34
  • 1
    You're welcome! Regarding what I said, It is not stated directly on the [docs](https://developers.google.com/maps/documentation/android-sdk/get-api-key#creating-api-keys) that it requires internet, but since it says there that "You must add an API key to any app that uses the SDK", and that "The API key is a unique identifier that authenticates requests associated with your project for usage and billing purposes", shows that it really was designed to be used online. – Yrll Nov 12 '22 at 23:44