maplibre / maplibre-native

MapLibre Native - Interactive vector tile maps for iOS, Android and other platforms.
https://maplibre.org
BSD 2-Clause "Simplified" License
888 stars 273 forks source link

Cant init map in emulator #2549

Closed WuMianzhi closed 1 week ago

WuMianzhi commented 1 week ago

Im the beginner in android develop, when i use maplibre in my app, just follow the step in started-guide , and i cant init and hints image

the result just like this: image

but it could be loaded normal in real device.

here is my code, please help me

in MainActivity.java

        super.onCreate(savedInstanceState);
        Log.d("TAG", "onCreate: " + checkOpenGLESVersion(this));

        // Using MapView requires calling MapLibre.getInstance() before inflating or creating the view.
        MapLibre.getInstance(this);

        // EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        mapView = findViewById(R.id.mapView);

        mapView.getMapAsync(mapLibreMap -> {
            mapLibreMap.setStyle("https://demotiles.maplibre.org/style.json");

            double[] padding = new double[]{1.0, 1.0, 1.0, 1.0};
            LatLng center = new LatLng(120.0, 30.0);
            double zoom = 12.0;
            double tilt = 1.0;
            double bearing = 90.0;

            CameraPosition cameraPosition = new CameraPosition(center, zoom, tilt, bearing, padding);
            mapLibreMap.setCameraPosition(cameraPosition);
        });

in activity_main.xml

    <org.maplibre.android.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />