简单测试一下andriod中的地图应用,没想到一个小小的应用也费了不少的事,记录一下,以备查.
首先要修改AndroidManifest.xml文件:
<!-- 加入引用库 -->
<uses-library android:name="com.google.android.maps" />
<!-- 加入权限 -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
然后修改Activity,注意要从MapActivity继承:
public class MainActivity extends MapActivity { ... }
下面是activity的一个简单示例:
public class MainActivity extends MapActivity {
private MapView mMapView;
private MapController mMapContraoller;
private GeoPoint mGeoPoint=new GeoPoint(30659259,104065762);
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mMapView=(MapView)findViewById(R.id.MapView01);
mMapView.setTraffic(true);
mMapView.setEnabled(true);
mMapView.setClickable(true);
mMapContraoller=mMapView.getController();
mMapContraoller.setZoom(12);
mMapContraoller.animateTo(mGeoPoint);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
activity的资源文件中填加mapview:
<com.google.android.maps.MapView
android:id="@+id/MapView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="067_6YH5q7XFvCHGX8HeK9FQf9pMrzQsax4hqOw"
/>
注意:
android:apiKey="067_6YH5q7XFvCHGX8HeK9FQf9pMrzQsax4hqOw"
要自己去申请,然后加上.