第9章位置服务与地图应用67820课程.pptVIP

  • 2
  • 0
  • 约1.6万字
  • 约 53页
  • 2016-09-26 发布于江苏
  • 举报
9.2 Google地图应用 9.2.2 使用Google地图 因为普通版本的Android SDK并不包含Google地图的开发扩展库,因此在建立工程时需将com.google.android.maps扩展库添加到工程中,这样就可以使用Google地图的所有功能 添加com.google.android.maps扩展库的方式是在创建工程时,在Build Target项中选择Google APIs,如下图所示 9.2 Google地图应用 9.2.2 使用Google地图 引入Google地图扩展库(图) 9.2 Google地图应用 9.2.2 使用Google地图 创建工程后,修改/res/layout/main.xml文件,布局文件中加入一个MapView控件,并设置刚获取的“地图密钥”。main.xml文件的完整代码如下 1 ?xml version=1.0 encoding=utf-8? 2 LinearLayout xmlns:android=/apk/res/android 3 android:orientation=vertical 4 android:layout_width=fill_parent 5 android:layout_height=fill_parent 6 TextView android:layout_width=fill_parent 7 android:layout_height=wrap_content 8 android:text=@string/hello/ 9 10 com.google.android.maps.MapView 11 android:id=@+id/mapview 12 android:layout_width=fill_parent 13 android:layout_height=fill_parent 14 android:enabled=true 15 android:clickable=true 16 android:apiKey=0mVK8GeO6WUzmtzGfNoqXI5KRW4oeh5ljVMoiCg/ 17 /LinearLayout 9.2 Google地图应用 9.2.2 使用Google地图 仅在布局中添加MapView控件,还不能够直接在程序中调用这个控件,还需要将程序本身设置成MapActivity(com.google.android.maps.MapActivity) MapActivity类负责处理显示Google地图所需的生命周期和后台服务管理 GoogleMapDemoActivity.java文件的完整代码为 1 package edu.hrbeu.GoogleMapDemo; 2 3 import com.google.android.maps.GeoPoint; 4 import com.google.android.maps.MapActivity; 5 import com.google.android.maps.MapController; 6 import com.google.android.maps.MapView; 7 8 import android.os.Bundle; 9 9.2 Google地图应用 9.2.2 使用Google地图 10 public class GoogleMapDemoActivity extends MapActivity { 11 private MapView mapView; 12 private MapController mapController; 13 14 @Override 15 public void onCreate(Bundle savedInstanceState) { 16 super.onCreate(savedInstanceState); 17 setContentView(R.layout.main); 18 19 mapView = (MapView)findViewById(R.id.mapview); 20 mapController = mapView.getController(); 21 22 Double lng = 126.676530486 * 1E6; 23 Double lat = 45.7698895661 * 1E6; 24 GeoPoint point = new

文档评论(0)

1亿VIP精品文档

相关文档