7.2 Google地图应用 7.2.2 使用Google地图 在建立工程时将com.google.android.maps的扩展库添加到工程中,这样就可以使用Google地图的所有功能 添加com.google.android.maps扩展库的方式是在创建工程时,在Build Target项中选择Google APIs 创建工程后,修改/res/layout/main.xml文件,在布局中加入一个MapView控件,并设置刚获取的“地图密钥” 7.2 Google地图应用 7.2.2 使用Google地图 main.xml文件的完整代码如下 ?xml version=1.0 encoding=utf-8? LinearLayout xmlns:android=/apk/res/android android:orientation=vertical android:layout_width=fill_parent android:layout_height=fill_parent TextView android:layout_width=fill_parent android:layout_height=wrap_content android:text=@string/hello/ com.google.android.maps.MapView android:id=@+id/mapview android:layout_width=fill_parent android:layout_height=fill_parent android:enabled=true android:clickable=true android:apiKey=0mVK8GeO6WUz4S94z52CIGSSlvlTwnrE4DsiA/ /LinearLayout 7.2 Google地图应用 7.2.2 使用Google地图 仅在布局中添加MapView控件,还不能够直接在程序中调用这个控件,还需要将程序本身设置成MapActivity(com.google.android.maps.MapActivity) MapActivity类负责处理显示Google地图所需的生命周期和后台服务管理 下面先给出整个GoogleMapDemo.java文件的完整代码 package edu.hrbeu.GoogleMapDemo; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapActivity; import com.google.android.maps.MapController; import com.google.android.maps.MapView; 7.2 Google地图应用 7.2.2 使用Google地图 import android.os.Bundle; public class GoogleMapDemo extends MapActivity { private MapView mapView; private MapController mapController; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapView = (MapView)findViewById(R.id.mapview); mapController = mapView.getController(); Double lng = 126.676530486 * 1E6; Double lat = 45.7698895661 * 1E6; GeoPoint point = new GeoPoint(Value(), Value()); 7.2 Google地图应用 7.2.2 使用Google地图 25. mapController.setCenter(point); mapController.setZoom(11); mapController.animateTo(point); mapView.setSatellite(false) } @Override protected boolean isRouteDi
您可能关注的文档
最近下载
- 电子病历系统应用水平四级实证材料通用模板(基本项部分)(2022版).doc VIP
- 实施指南《GB_T37306.1-2019金属材料疲劳试验变幅疲劳试验第1部分:总则、试验方法和报告要求》实施指南.docx VIP
- 中药生产监督管理专门规定-培训.pptx VIP
- 大学在线开放课程建设实施方案.docx VIP
- 电子病历系统应用水平四级实证材料通用模板(选择项部分)(2024版).doc VIP
- 北师大版六年级数学下册第一单元《圆柱与圆锥》课件.pptx VIP
- PEP人教版小学英语四年级下册阅读理解练习36篇.pdf VIP
- 2025年云南省中考数学——26题二次函数降次幂精选题35道.docx VIP
- 《化妆品中凝血酸(氨甲环酸)的测定 高效液相色谱法》.pdf VIP
- 厂房建设投资估算表.xls VIP
原创力文档

文档评论(0)