osmdroid和显示地图

时间:2014-10-21 08:41:06

标签: android eclipse osmdroid

我无法从Mapnik显示我的地图,我不知道是什么问题。 有谁可以帮助我吗!我需要帮助! 这是我的日志和我的程序

MainActivity

    package com.formation.mapnick;

import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;

import android.app.Activity;
import android.os.Bundle;
//import android.view.Menu;
//import android.view.MenuItem;

public class MainActivity extends Activity {

    //the MapView variable:
    private MapView m_mapView;
    private int MAP_DEFAULT_ZOOM = 15;
    private double MAP_DEFAULT_LATITUDE = 49.292531;
    private double MAP_DEFAULT_LONGITUDE = -12.276610;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //Find the MapView controller in that layout
        m_mapView = (MapView) findViewById(R.id.mapview);
        m_mapView.setBuiltInZoomControls(true);
        m_mapView.setClickable(true);
        m_mapView.setMultiTouchControls(true);
        m_mapView.setUseDataConnection(true);
        m_mapView.getController().setZoom(MAP_DEFAULT_ZOOM);
        m_mapView.getController().setCenter(new GeoPoint(MAP_DEFAULT_LATITUDE,MAP_DEFAULT_LONGITUDE));
        m_mapView.setTileSource(TileSourceFactory.MAPNIK);

    }
}

AndroidManifest

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.formation.mapnick"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="17"
        android:targetSdkVersion="20" />

     <supports-screens 
    android:anyDensity="true"
    android:resizeable="false"
    android:largeScreens="true"
    android:normalScreens="true"
    />

    <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="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

my activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="${relativePackage}.${activityClass}" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

     <org.osmdroid.views.MapView
            android:id="@+id/mapview"
            android:layout_width="match_parent" 
            android:layout_height="match_parent"
            android:enabled="true"      
            android:clickable="true"
            android:apiKey="@string/apiKey"
        />  


</RelativeLayout>

我的日志:

10-21 08:24:42.709: E/Trace(1112): error opening trace file: No such file or directory (2)
10-21 08:24:43.180: E/dalvikvm(1112): Could not find class 'org.osmdroid.views.MapView', referenced from method com.formation.mapnick.MainActivity.onCreate
10-21 08:24:43.199: W/dalvikvm(1112): VFY: unable to resolve check-cast 979 (Lorg/osmdroid/views/MapView;) in Lcom/formation/mapnick/MainActivity;
10-21 08:24:43.199: D/dalvikvm(1112): VFY: replacing opcode 0x1f at 0x000f
10-21 08:24:43.229: D/dalvikvm(1112): DexOpt: unable to opt direct call 0x18bf at 0x3e in Lcom/formation/mapnick/MainActivity;.onCreate
10-21 08:24:43.609: D/AndroidRuntime(1112): Shutting down VM
10-21 08:24:43.609: W/dalvikvm(1112): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
10-21 08:24:43.661: E/AndroidRuntime(1112): FATAL EXCEPTION: main
10-21 08:24:43.661: E/AndroidRuntime(1112): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.formation.mapnick/com.formation.mapnick.MainActivity}: android.view.InflateException: Binary XML file line #12: Error inflating class org.osmdroid.views.MapView
10-21 08:24:43.661: E/AndroidRuntime(1112):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
10-21 08:24:43.661: E/AndroidRuntime(1112):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
10-21 08:24:43.661: E/AndroidRuntime(1112):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-21 08:24:43.661: E/AndroidRuntime(1112):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
10-21 08:24:43.661: E/AndroidRuntime(1112):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-21 08:24:43.661: E/AndroidRuntime(1112):     at android.os.Looper.loop(Looper.java:137)
10-21 08:24:43.661: E/AndroidRuntime(1112):     at android.app.ActivityThread.main(ActivityThread.java:5041)
10-21 08:24:43.661: E/AndroidRuntime(1112):     at java.lang.reflect.Method.invokeNative(Native Method)
10-21 08:24:43.661: E/AndroidRuntime(1112):     at java.lang.reflect.Method.invoke(Method.java:511)
10-21 08:24:43.661: E/AndroidRuntime(1112):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
10-21 08:24:43.661: E/AndroidRuntime(1112):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
10-21 08:24:43.661: E/AndroidRuntime(1112):     at dalvik.system.NativeStart.main(Native Method)
10-21 08:24:43.661: E/AndroidRuntime(1112): Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class org.osmdroid.views.MapView
10-21 08:24:43.661: E/AndroidRuntime(1112):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
10-21 08:24:43.661: E/AndroidRuntime(1112):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
10-21 08:24:43.661: E/AndroidRuntime(1112):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
10-21 08:24:43.661: E/AndroidRuntime(1112):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
10-21 08:24:43.661: E/AndroidRuntime(1112):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
10-21 08:24:43.661: E/AndroidRuntime(1112):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
10-21 08:24:43.661: E/AndroidRuntime(1112):     at android.app.Activity.setContentView(Activity.java:1881)
10-21 08:24:43.661: E/AndroidRuntime(1112):     at com.formation.mapnick.MainActivity.onCreate(MainActivity.java:24)
10-21 08:24:43.661: E/AndroidRuntime(1112):     at android.app.Activity.performCreate(Activity.java:5104)
10-21 08:24:43.661: E/AndroidRuntime(1112):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
10-21 08:24:43.661: E/AndroidRuntime(1112):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
10-21 08:24:43.661: E/AndroidRuntime(1112):     ... 11 more
10-21 08:24:43.661: E/AndroidRuntime(1112): Caused by: java.lang.ClassNotFoundException: Didn't find class "org.osmdroid.views.MapView" on path: /data/app/com.formation.mapnick-1.apk
10-21 08:24:43.661: E/AndroidRuntime(1112):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
10-21 08:24:43.661: E/AndroidRuntime(1112):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
10-21 08:24:43.661: E/AndroidRuntime(1112):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
10-21 08:24:43.661: E/AndroidRuntime(1112):     at android.view.LayoutInflater.createView(LayoutInflater.java:552)
10-21 08:24:43.661: E/AndroidRuntime(1112):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
10-21 08:24:43.661: E/AndroidRuntime(1112):     ... 21 more
10-21 08:24:48.429: I/Process(1112): Sending signal. PID: 1112 SIG: 9

任何想法?我已经在手机上测试了它但没有结果!

0 个答案:

没有答案