OpenStreetMap import and usage are required as I work on an Android application. I use the osmdroid library 6.0.1 because of this. Sadly, because of java.net, the tiles do not load when I launch the application. UnknownHostException. When I start the application, I receive the following results on both the emulator and my smartphone: Emulator - Screenshot of an application
Here is the instance when the rule is frequently broken when I pan and zoom the map.
W/OsmDroid: UnknownHostException downloading MapTile: /0/0/0 : java.net.UnknownHostException: Unable to resolve host "a.tile.openstreetmap.org": No address associated with hostname
I/OsmDroid: Tile loader can't continue: /0/0/0
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
W/OsmDroid: UnknownHostException downloading MapTile: /0/0/0 : java.net.UnknownHostException: Unable to resolve host "b.tile.openstreetmap.org": No address associated with hostname
I/OsmDroid: Tile loader can't continue: /0/0/0
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MapActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
activity_map.xml:
<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>
MapActivity.java:
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 MapActivity extends AppCompatActivity {
MapView map = null;
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Context ctx = getApplicationContext();
Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));
setContentView(R.layout.activity_map);
map = (MapView) findViewById(R.id.map);
map.setTileSource(TileSourceFactory.MAPNIK);
IMapController mapController = map.getController();
GeoPoint startPoint = new GeoPoint(48.8583, 2.2944);
mapController.setCenter(startPoint);
}
}
Do you have any ideas as to what might be wrong?