Карта мира OSMDroid не отображается - PullRequest
0 голосов
/ 15 декабря 2018

Я следую учебнику по OSMDroid, представленному в здесь :

Но я сталкиваюсь с некоторыми проблемами, я сделал все, как в учебнике, однако, когдаЯ запускаю приложение, оно должно показывать Карта мира , однако я вижу только сетку и кнопки масштабирования.

Вот мой код для макета и MainActivity:

Макет:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    >

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <org.osmdroid.views.MapView android:id="@+id/map"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />

    </LinearLayout>



    <org.osmdroid.views.MapView
        android:id="@+id/mapview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tilesource="Mapnik" />

</android.support.design.widget.CoordinatorLayout>

Активность:

import android.content.Context;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import org.osmdroid.api.IMapController;
import org.osmdroid.config.Configuration;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;


public class MainActivity extends AppCompatActivity{
    MapView map = null;


    @Override
    public void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Context ctx = getApplicationContext();
        Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));

        map = (MapView) findViewById(R.id.map);
        map.setTileSource(TileSourceFactory.MAPNIK);
        map.setBuiltInZoomControls(true);
        map.setMultiTouchControls(true);
        IMapController mapController = map.getController();
        mapController.setZoom(9.5);
        GeoPoint startPoint = new GeoPoint(48.8583, 2.2944);
        mapController.setCenter(startPoint);
    }

    public void onResume(){
        super.onResume();
        map.onResume(); 
    }

    public void onPause(){
        super.onPause();
        map.onPause();  
    }
}

Разве карта мира не должна появляться после запуска?

Заранее спасибо!

1 Ответ

0 голосов
/ 02 июня 2019

просто измените .xml на фрагмент ниже

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <org.osmdroid.views.MapView android:id="@+id/map"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />

    </LinearLayout>
...