I am trying to implement OpenStreetMap in android studio. I successfully added the libraries as shown below.
This is my MainActivity:
package com.example.re.osm;
import org.osmdroid.views.MapController;
import org.osmdroid.views.MapView;
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.example.harjotkaur.osm.R;
public class MainActivity extends Activity {
private MapView myOpenMapView;
private MapController myMapController;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myOpenMapView = (MapView)findViewById(R.id.openmapview);
myOpenMapView.seharjotkaurtBuiltInZoomControls(true);
myMapController = myOpenMapView.getController();
myMapController.setZoom(4);
}
}
This is my build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.example.re.osm"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile files('libs/slf4j-android-1.5.8.jar')
compile files('libs/osmdroid-android-3.0.8.jar')
}
This is my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.re.osm"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<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:icon="@drawable/ic_launcher"
android:label="OSM" >
<activity
android:name=".MainActivity"
android:label="OSM" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
But when I run the aplication, I get to see only small rectangles and not the map. How should I fix this? What steps should I follow?
Any ideas are appreciated?
Thanks
Replace
import com.exercise.OpenStreetMapView.R;
with this:
import com.example.re.osm.R;