GOOGLE MAP API是Android的靓点之一,我们可以创建一个MapActivity的子类,将MapView显示于其上即可,可以用MapController来控制显示的坐标、地图模式和视野高度,处理起来非常简单。
完整代码如下: public class MapTest extends MapActivity { private MapView mapView; private MapController mc; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mapview); mapView = (MapView) findViewById(R.id.map); mapView.setTraffic(true); mc = mapView.getController(); GeoPoint gp = new GeoPoint((int) (30.659259 * 1000000), (int) (104.065762 * 1000000)); //地理坐标 mc.animateTo(gp); mc.setZoom(12); } @Override protected boolean isRouteDisplayed() { return false; } } mapview.xml内容如下: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <com.google.android.maps.MapView android:id="@+id/map" android:layout_width="fill_parent" android:layout_height="fill_parent" android:enabled="true" android:clickable="true" android:apiKey="0mHnPl2NS9XPKx6pKwJriV2Wj-mEHSh71yyX_SQ" /> </RelativeLayout> 注意: 1、你要申请一个自己的apiKey; 2、不要忘了设置互联网访问权限。