Anroid调用系统的mapView
来源:互联网 发布:如何关闭135和445端口 编辑:程序博客网 时间:2024/06/04 16:23
Android Google map使用
1、使用Android Google Map Api之前必须检测系统中是否安装了Google map 应用,检测方法如下:
protected boolean checkGoogleMap(){lean isInstallGMap = false; List<PackageInfo>packs = getPackageManager().getInstalledPackages(0);for (int i = 0; i < packs.size(); i++) {PackageInfo p = packs.get(i);if (p.versionName == null) { // system packages continue;}if ("com.google.android.apps.maps".equals(p.packageName)) { isInstallGMap = true; break;}}return isInstallGMap;}
2、当检测出系统中没有安装Google map 应用时,可以转向Web版的Google map 来访问,如下:
Intent it = new Intent(Intent.ACTION_VIEW, Uri.parse("http://ditu.google.cn/maps?hl=zh&mrt=loc&q="+weiduExtra+","+jingduExtra+"")); startActivity(it); 注意:使用此方法需在AndroidManifest.xml中加入网络访问权限<uses-permission android:name="android.permission.INTERNET"></uses-permission>
3、当检测出系统中已经安装Google map 应用时,我们就可以使用Google map api 了,使用方法如下:
1)方法一:
Intent it = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:"+weiduExtra+","+jingduExtra));startActivity(it);注意:使用此方法需在AndroidManifest.xml中加入相应的访问权限<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.INTERNET" />
2)方法二:
可以创建一个MapActivity的子类,将MapView显示于其上即可,可以用MapController来控制显示的坐标、地图模式和视野高度,处理起来非常简单。
Java代码 :
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; } } public class MapTest extends MapActivity {private MapView mapView;private MapController mc;@Overridepublic 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);} @Overrideprotected boolean isRouteDisplayed() {return false;}}mapview.xml内容如下: 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> <?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>
注意:
A、使用此方法需在AndroidManifest.xml中加入相应的访问权限。
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.INTERNET" />;
B、你要申请一个自己的apiKey。
- Anroid调用系统的mapView
- anroid Intent调用系统组件的方法
- SHARP ANROID 系统ROOT的思路
- Anroid调用系统相机或相册获取图片
- Android--MapView.第一个简单的MapView
- 生成anroid系统数字证书
- MapView的apiKey
- MapView的基本用法
- mapView的基本使用
- mapView
- anroid 系统拍照程序
- Anroid中的系统Intent大全
- android 的mapview的apikey
- android 的mapview的apikey
- android 的mapview的apikey
- 基于MapView实现的MapNavigator
- MapView 地图的基本使用
- anroid
- object-c 第一个程序(helloword)有图有真相
- 禁用浏览器滚动条的解决方案
- AndEngine-----Example中Simple例子的总结
- Javascript basics - types and variables
- 开开心心学算法--一种排序
- Anroid调用系统的mapView
- 为什么极少数android板子会打印Uncompressing Linux... done, booting the kernel就不动了
- c#读写二进制
- 创建WBS要点
- OpenCv xml
- VB6获取快捷方式lnk文件的指向绝对路径
- javascript变量和数据类型
- App今日免费:萌熊划线解谜 Oh my fish
- link标签和script标签跑到body下面,网页顶部有空白,UTF-8 BOM问题