一、MapView申请apiKey
Map API Key谷歌给升级了,找了好久才找到最新的获取apiKey的方法,参考地址:http://blog.csdn.net/sym207/article/details/24458685
二、MapView控件的使用
1.建立mapview.xml布局文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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: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:
package com.willawn.androidtest.test;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.ZoomControls;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
public class MapViewActivity extends MapActivity {
// 线性布局
private LinearLayout linearLayout;
// 地图视图
private MapView mapView;
// 缩放控制
private ZoomControls mZoom;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapview);
linearLayout = (LinearLayout) findViewById(R.id.zoomView);
mapView = (MapView) findViewById(R.id.mapView);
mapView.getController().setCenter(new GeoPoint(39971036,116314659));
mapView.getController().setZoom(10);
mZoom = (ZoomControls) mapView.getZoomControls();
linearLayout.addView(mZoom);
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}
三、使用中遇到的问题解决方法
参考地址:http://blog.csdn.net/sym207/article/details/24458609