Search code examples
androidgoogle-mapsgoogle-maps-api-2

Store Google Map once it loads in android device


Unfortunately i have not found any answer to store the Google map in SO.

I'm currently working in a Map application which will show user's friends locations. But when I'm clicking on a new friend it loads the map again and consumes resource.

Is there any way to store the map once it loads and not go to the Map Server again when required. So I can just put the new location values when required and it will use the stored map to show.

I load the map in general way like below:

switch (GooglePlayServicesUtil
                .isGooglePlayServicesAvailable(getActivity())) {
        case ConnectionResult.SUCCESS:
        mapView = (MapView) view.findViewById(R.id.map);
        mapView.onCreate(savedInstanceState);

        if (mapView != null) {
               map = mapView.getMap();
               map.getUiSettings().setMyLocationButtonEnabled(false);
               map.setMyLocationEnabled(true);
               CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), 15);
               map.animateCamera(cameraUpdate);
            }
            break;
        case ConnectionResult.SERVICE_MISSING:

            break;
        case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:

            break;

EDIT: Or Is there any way to prevent the map to loads again and again?


Solution

  • The Google map view should already cache the map tiles, so if you're seeing lag then make sure you aren't doing any unnecessary work before displaying the map.

    If you want a static map of a single coordinate, look into Google Maps Static Maps API. Your app could fetch the image once, cache it itself, then display it whenever the user has to see it. When the user changes their location (I'm assuming it's not often) then refetch the static map.

    As of January 2017 the link should be https://developers.google.com/maps/documentation/static-maps/intro