Osmdroid的MapView不显示地图

时间:2014-01-20 21:02:27

标签: java android osmdroid

不显示地图=(。我使用osmdroid libs显示它们,使用Samsung Tab 2 10.1“进行调试。我试图搜索问题,大多数答案是:”你没有在你的清单中添加权限“。我添加了所有权限,但地图仍然没有显示,我也看到,当一些模拟器没有SD卡时,地图没有显示,我的平板电脑上没有SD卡可能就是这个原因。如果是所以,我该怎么做才能解决问题,如果不是,那么真正的问题是什么呢。

我得到了这个main.java

package com.example.tradersamurai;

import org.osmdroid.DefaultResourceProxyImpl;
import org.osmdroid.ResourceProxy;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.Menu;
import android.widget.Button;
import android.view.View;
import android.widget.TextView;


public class MainActivity extends Activity 
{
    // Layout elements
    Button btnAddMark;
    Button btnShowPath;

    TextView tvPathInfo;
    MapView mapView;
    // 

    CityGraph minimap;

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

        // --------------------------------------------------------------------------------------------
        btnAddMark  = (Button) findViewById(R.id.btn_add_mark);
        btnShowPath = (Button) findViewById(R.id.btn_show_path);

        tvPathInfo = (TextView) findViewById(R.id.tv_path_info);
        mapView  = (MapView) findViewById(R.id.mapview);
        mapView.setTileSource(TileSourceFactory.MAPNIK);
        mapView.setBuiltInZoomControls(true);
        mapView.setMultiTouchControls(true);
        mapView.setUseDataConnection(true);

        minimap = new CityGraph();  
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) 
    {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    public void btn_show_path_click(View v)
    {
        tvPathInfo.setText("show path");
    }

    public void btn_add_mark_on_click(View v)
    {
        if(minimap.get_size() + 1 > CityGraph.MAX_SIZE)
            tvPathInfo.setText("Out of range");
        else
        {
            minimap.add_new_vertex();
            tvPathInfo.setText("Added OK");
        }
    }
}

我的清单

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <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" />

    <uses-feature android:name="android.hardware.location.network" />
    <uses-feature android:name="android.hardware.location.gps" />   
    <uses-feature android:name="android.hardware.wifi" />    

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.tradersamurai.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>

和布局

<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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/btn_show_path"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/btn_add_mark"
        android:layout_below="@+id/btn_add_mark"
        android:layout_marginTop="24dp"

        android:onClick="btn_show_path_click"       

        android:text="@string/btn_display_path_info_text" />

    <Button
        android:id="@+id/btn_add_mark"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="76dp"
        android:layout_marginTop="35dp"

        android:onClick="btn_add_mark_on_click"

        android:text="@string/btn_add_mark_text" />

    <TextView
        android:id="@+id/tv_path_info"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/btn_show_path"
        android:layout_below="@+id/btn_show_path"
        android:layout_marginTop="46dp"
        android:text="@string/tv_path_info" />

    <org.osmdroid.views.MapView
        android:id="@+id/mapview"
        android:layout_width="800dp"
        android:layout_height="fill_parent"
        android:layout_centerVertical="true"
        android:clickable="true" >

    </org.osmdroid.views.MapView>

</RelativeLayout>

0 个答案:

没有答案