Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Map loading very slow/not loading at all in started activity until clicking on it

When starting a new map activity the map loads really slow and doesn't start the loading until clicking the screen.

The Layout is the following:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.example.android.momintuition.DirectionsActivity">

    <com.google.android.gms.maps.MapView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:map="http://schemas.android.com/apk/res-auto"
        android:id="@+id/mapView"
        android:paddingTop="62px"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clickable="true"
        map:uiCompass="true"
        map:zOrderOnTop="true"
        map:uiZoomControls="true"
        android:background="#00000000" />
</RelativeLayout>

The new activity looks like this:

public class DirectionsActivity extends AppCompatActivity implements OnMapReadyCallback {


    GoogleMap mMap; // Might be null if Google Play services APK is not available.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_directions);
        MapView mv = (MapView) findViewById(R.id.mapView);
        mv.onCreate(savedInstanceState);
        mMap = mv.getMapAsync(this);

    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
         this.map = googleMap;
         CameraUpdate cameraUpdate =
                                CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10);
         map.animateCamera(cameraUpdate);
    }
}

I am new to Android. Am I missing something? Thank you!

like image 630
raluca Avatar asked Oct 02 '15 14:10

raluca


People also ask

Why is my Maps taking forever to load?

Clear app data Google Maps stores data like shared locations, saved locations, and map tiles on your phone or tablet. Clearing this data will do the following things: Delete cache (including search suggestions, direction searches, map tiles, and activity page content stored on your device) Delete cookies.

Why is Google Maps not loading?

Clear the app's cache & data On your Android phone or tablet, open the Settings app . Tap Apps & notifications. Follow the steps on your device to find the Maps app. After you select the app, storage & cache options should be available.

What is wrong with Google Maps lately?

More and more Android users ended up struggling with all kinds of problems in Google Maps, including broken navigation, GPS connection issues, audible guidance not working, and freezes occurring all of a sudden when the app is minimized.


1 Answers

The problem in this case was that I didn't implement the following methods(even if it was specified in the documentation):

    @Override
    public void onResume() {
        mapView.onResume();
        super.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
        mapView.onPause();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mapView.onDestroy();
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
        mapView.onLowMemory();
    }

It is counterintuitive to me why this methods might affect showing the map but it does fix the problem.

like image 114
raluca Avatar answered Oct 09 '22 02:10

raluca