android中的MapView是Totally Black

时间:2013-02-08 04:50:01

标签: android

我在我的应用程序中使用mapView。在我的模拟器上我得到黑屏而不是这张地图。我添加了权限并添加了<uses-library android:name="com.google.android.maps"/>标记。当我在我的模拟器上运行我的应用时,它会显示黑屏而不是地图。

public class MainActivity extends MapActivity {

    MapView mv;
    MapController mc;
    GeoPoint mPoint;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mv = (MapView) findViewById(R.id.map);
        mv.setBuiltInZoomControls(true);
        mv.setSatellite(true);
        mc = mv.getController();
        mPoint = new GeoPoint(70, 30);
        mc.animateTo(mPoint);
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), android.R.drawable.sym_action_email);
        MarkerOverlay mo = new MarkerOverlay(bitmap);
        mv.getOverlays().add(mo);
    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }
    class MarkerOverlay extends Overlay{
        Bitmap marker;
        public MarkerOverlay(Bitmap bitmap) {
            this.marker = bitmap;
        }
        @Override
        public void draw(Canvas canvas, MapView mapView, boolean shadow) {
            super.draw(canvas, mapView, shadow);
            Point p = new Point();
            mapView.getProjection().toPixels(mPoint, p);
            canvas.drawBitmap(marker, p.x, p.y,null);
        }
    }


}

layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <com.google.android.maps.MapView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/map"
        android:apiKey="0N2w90XW-PeM2vP4D4yfM2CoLRfIF6nnZAr2Cqg" />

</LinearLayout>

的manifest.xml

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

    <uses-sdk
        android:minSdkVersion="5"
        android:targetSdkVersion="10" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

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

2 个答案:

答案 0 :(得分:0)

好。我觉得我的项目有些不对劲。我删除了我当前的项目并构建了一个新项目并且运行正常。

答案 1 :(得分:0)

mc.setZoom(17);
  

设置缩放级别,获取默认缩放级别1.参阅文章https://developers.google.com/maps/documentation/android/v1/reference/com/google/android/maps/MapView