Android Map新用法:MapFragment应用介绍
更新时间:2013年01月06日 17:16:19 作者:
MapView ,MapActivity 这种的局限在于,必须要继承MapActivity,否则无法使用MapView,但是,MapFragment 这种的局限在于,必须要安装Google Play Service ,也就是说必须是原生rom。而且sdk要在12以上
1.MapView ,MapActivity 这种的局限在于,必须要继承MapActivity,否则无法使用MapView。纠结就在于此。但是,最新官网上已经弃用了这糟粕的MapActivity。
Version 1 of the Google Maps Android API as been officially deprecated as of December 3rd, 2012. This means that from March 3rd, 2013 you will no longer be able to request an API key for this version. No new features will be added to Google Maps Android API v1. However, apps using v1 will continue to work on devices. Existing and new developers are encouraged to use Google Maps Android API v2.
2.MapFragment 这种的局限在于,必须要安装Google Play Service ,也就是说必须是原生rom。而且sdk要在12以上。我蛋疼了。
3.WebView 貌似很轻松的集成进来,但没有实践就木有发言权。
第一种方式我先略过了。大家都知道。说第二种,第三种会了再补上
MapFragment是刚出的google官方包,要集成进来还是挺麻烦的。官网链接 https://developers.google.com/maps/documentation/android/start
首先要到google conlose 添加api access权限,拿到apikey,创建一个project ,然后到services里把Google Maps Android API v2打开,再到api access里把你的project的keystore的SHA1和包名填进去,拿到唯一的api key
打开sdk manager--在Extras里把Android Support Libaray 和 Google Play Services都安装,lib和samples都在sdk_path/extra/google/google_play_services下。导入../lib_project作为自己项目的libaray
这一步完了之后在manifest.xml文件里添加权限和api key。代码如下
<permission
android:name="com.example.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
com.example替换成自己project的package
<uses-permission android:name="com.example.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!--My Location-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!--Maps API needs OpenGL ES2.0.-->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
放在application声明里
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="appkey"/>
在layout xml里加入MapFragment声明
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"/>
activity不变,extends Activity就可以了。 不需要继承MapActivity了。
注意,debug状态下是不可以显示地图的,一定要在正式签名下map才会显示出来。
install下应该就能看到map了
还有不懂的就多看看官方文档把,介绍的很清楚。以上只是方便我自己记忆。
Version 1 of the Google Maps Android API as been officially deprecated as of December 3rd, 2012. This means that from March 3rd, 2013 you will no longer be able to request an API key for this version. No new features will be added to Google Maps Android API v1. However, apps using v1 will continue to work on devices. Existing and new developers are encouraged to use Google Maps Android API v2.
2.MapFragment 这种的局限在于,必须要安装Google Play Service ,也就是说必须是原生rom。而且sdk要在12以上。我蛋疼了。
3.WebView 貌似很轻松的集成进来,但没有实践就木有发言权。
第一种方式我先略过了。大家都知道。说第二种,第三种会了再补上
MapFragment是刚出的google官方包,要集成进来还是挺麻烦的。官网链接 https://developers.google.com/maps/documentation/android/start
首先要到google conlose 添加api access权限,拿到apikey,创建一个project ,然后到services里把Google Maps Android API v2打开,再到api access里把你的project的keystore的SHA1和包名填进去,拿到唯一的api key
打开sdk manager--在Extras里把Android Support Libaray 和 Google Play Services都安装,lib和samples都在sdk_path/extra/google/google_play_services下。导入../lib_project作为自己项目的libaray
这一步完了之后在manifest.xml文件里添加权限和api key。代码如下
复制代码 代码如下:
<permission
android:name="com.example.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
com.example替换成自己project的package
复制代码 代码如下:
<uses-permission android:name="com.example.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!--My Location-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!--Maps API needs OpenGL ES2.0.-->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
放在application声明里
复制代码 代码如下:
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="appkey"/>
在layout xml里加入MapFragment声明
复制代码 代码如下:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"/>
activity不变,extends Activity就可以了。 不需要继承MapActivity了。
注意,debug状态下是不可以显示地图的,一定要在正式签名下map才会显示出来。
install下应该就能看到map了
还有不懂的就多看看官方文档把,介绍的很清楚。以上只是方便我自己记忆。
相关文章
Android编程ProgressBar自定义样式之动画模式实现方法
这篇文章主要介绍了Android编程ProgressBar自定义样式之动画模式实现方法,涉及Android动画模式的布局技巧,非常具有实用价值,需要的朋友可以参考下2015-10-10Android xUtils更新到3.0后的基本使用规则详解
xUtils是基于android的开发框架,简化了很多的开发步骤,可以说是非常好的开发工具。下面小编给大家带来了Android xUtils更新到3.0后的基本使用规则详解,感兴趣的朋友一起学习吧2016-08-08Kotlin文件读写与SharedPreferences存储功能实现方法
SharedPreferences是安卓平台上一个轻量级的存储类,用来保存应用的一些常用配置,比如Activity状态,Activity暂停时,将此activity的状态保存到SharedPereferences中;当Activity重载,系统回调方法onSaveInstanceState时,再从SharedPreferences中将值取出2022-12-12
最新评论