MapView使用示例
一、MapView申请apiKey
打开Eclipse--->Windows--->Preferences--->Android--->Build
查看默认的debugkeystore位置,我的是C:\Users\wh\.android\debug.keystore
在cmd中执行
keytool-list-aliasandroiddebugkey-keystore"C:\Users\wh\.android\debug.keystore"-storepassandroid-keypassandroid
双引号中的为你keystore位置
执行结果:
androiddebugkey,2009-2-17,keyEntry,
认证指纹(MD5):XX:XX:XX:XX:XX:XX:XX:XX.............
打开http://code.google.com/intl/zh-CN/android/maps-api-signup.html
填入你的认证指纹(MD5)即可获得apiKey了
layout中加入MapView
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="XXXXXXXXXXXXXXXXXXXXXXXXXXXX"/>
二、MapView控件的使用
1.建立mapview.xml布局文件:
<?xmlversion="1.0"encoding="utf-8"?>
<RelativeLayoutxmlns: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:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="0NmBYax5wIVpt1zmwv7RnvNczoF2Ftwzd9yDduA"/>
<LinearLayout
android:id="@+id/zoomView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/mapView"
android:layout_centerHorizontal="true">
</LinearLayout>
</RelativeLayout>
1.新建MapViewActivity继承MapActivity:
packagecom.willawn.androidtest.test;
importandroid.os.Bundle;
importandroid.widget.LinearLayout;
importandroid.widget.ZoomControls;
importcom.google.android.maps.GeoPoint;
importcom.google.android.maps.MapActivity;
importcom.google.android.maps.MapView;
publicclassMapViewActivityextendsMapActivity{
//线性布局
privateLinearLayoutlinearLayout;
//地图视图
privateMapViewmapView;
//缩放控制
privateZoomControlsmZoom;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.mapview);
linearLayout=(LinearLayout)findViewById(R.id.zoomView);
mapView=(MapView)findViewById(R.id.mapView);
mapView.getController().setCenter(newGeoPoint(39971036,116314659));
mapView.getController().setZoom(10);
mZoom=(ZoomControls)mapView.getZoomControls();
linearLayout.addView(mZoom);
}
@Override
protectedbooleanisRouteDisplayed(){
returnfalse;
}
}