0

我在我的应用程序中使用 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);
        }
    }


}

布局.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>

清单.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>
4

2 回答 2

0

好的。我认为我的项目出了点问题。我删除了我当前的项目并建立了一个新项目,它运行良好。

于 2013-02-08T06:26:20.227 回答
0
mc.setZoom(17);

设置您的缩放级别,他们获得默认缩放级别 1.Refer 文章https://developers.google.com/maps/documentation/android/v1/reference/com/google/android/maps/MapView

于 2013-02-08T09:08:57.873 回答