2017-08-25 89 views
0

我想在android studio中實現OpenStreetMap。我成功添加了如下所示的庫。實施OpenStreetMap的錯誤

enter image description here

這是我的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); 
     } 

    } 

這是我的build.gradle文件:

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') 

} 

這是我的清單文件:

<?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> 

但是當我運行應用程序時,我只能看到小矩形而不看圖。 我應該如何解決這個問題?我應該遵循哪些步驟?

任何想法都讚賞?

感謝

+1

當前osmdroid庫的版本是5.6.5?可能五歲。 –

+0

我無法下載5.6.5 osmdroid庫。它帶我到這個頁面:https://jar-download.com/explore-java-source-code.php?a = osmdroid-geopackage&g = org.osmdroid&v = 5.6.5&downloadable = 0 我應該使用哪個版本? – Thomas

+0

按照osmdroid頁面上的說明:https://osmdroid.github.io/osmdroid/並使用gradle依賴關係。如果你不能使用gradle,你可以在這裏下載:https://github.com/osmdroid/osmdroid/releases –

回答

1

更換

import com.exercise.OpenStreetMapView.R; 

這一點:你爲什麼要這麼用古代版本(3.0.8)

import com.example.re.osm.R; 
+0

我用導入語句更新了我的問題。我應該改變什麼? – Thomas

+0

@Thomas我編輯了我的答案。你試過了嗎?如果它不起作用,請在問題中添加包導入。 – waleedsarwar86