今天学习了google map的简单开发,此篇博文主要内容是:在android手机上显示google map。
下面就来完成上面所提及的功能:
1、首先要在AndroidManifest.xml中添加the standard Android library,在AndroidManifest.xml的application节点中添加如下内容:
<uses-library android:name="com.google.android.maps" />
另外还要开通网络权限,在manifest的child节点中添加如下:
<uses-permission android:name="android.permission.INTERNET" />
2、打开res/layout/main.xml,在里面添加com.google.android.maps.MapView节点:
<?xml version="1.0" encoding="utf-8"?> <com.google.android.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mapview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:clickable="true" android:apiKey="0JF2BOEcpjLIf3HVmXn28EL-ahyk_mJbHBICUeg" />
<!-- 这个apiKey是我申请的,各不一样,你们要用使用自己的apiKey -->
3、我们要把自己写的Activity类实现MapActivity类。
public class googlemap1 extends MapActivity {
4、必须重写MapActivity类isRouteDisplayed()方法
@Override
protected boolean isRouteDisplayed() {
return false;
}
5、添加onCreate()回调方法:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true); //设置mapView显示用于缩放的工具条 }
}
到此我们就可以获得google map显示在手机屏幕上了,当然我们不仅仅是使用google map在手机上简单的显示而已,下面我们在地图上添加OverlayItem(地图上显示的标记)。详情请参见 (Google Map(二))