Android Map新用法:MapFragment應(yīng)用介紹
1.MapView ,MapActivity 這種的局限在于,必須要繼承MapActivity,否則無法使用MapView。糾結(jié)就在于此。但是,最新官網(wǎng)上已經(jīng)棄用了這糟粕的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 貌似很輕松的集成進(jìn)來,但沒有實(shí)踐就木有發(fā)言權(quán)。
第一種方式我先略過了。大家都知道。說第二種,第三種會(huì)了再補(bǔ)上
MapFragment是剛出的google官方包,要集成進(jìn)來還是挺麻煩的。官網(wǎng)鏈接 https://developers.google.com/maps/documentation/android/start
首先要到google conlose 添加api access權(quán)限,拿到apikey,創(chuàng)建一個(gè)project ,然后到services里把Google Maps Android API v2打開,再到api access里把你的project的keystore的SHA1和包名填進(jìn)去,拿到唯一的api key
打開sdk manager--在Extras里把Android Support Libaray 和 Google Play Services都安裝,lib和samples都在sdk_path/extra/google/google_play_services下。導(dǎo)入../lib_project作為自己項(xiàng)目的libaray
這一步完了之后在manifest.xml文件里添加權(quán)限和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狀態(tài)下是不可以顯示地圖的,一定要在正式簽名下map才會(huì)顯示出來。
install下應(yīng)該就能看到map了
還有不懂的就多看看官方文檔把,介紹的很清楚。以上只是方便我自己記憶。
相關(guān)文章
Rocksdb?Memtable數(shù)據(jù)結(jié)構(gòu)源碼解析
這篇文章主要為大家介紹了Rocksdb?Memtable數(shù)據(jù)結(jié)構(gòu)源碼解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11
Android實(shí)現(xiàn)在一個(gè)activity中添加多個(gè)listview的方法
這篇文章主要介紹了Android實(shí)現(xiàn)在一個(gè)activity中添加多個(gè)listview的方法,分析了Activity中添加listview的原理與具體實(shí)現(xiàn)方法,需要的朋友可以參考下2016-08-08
Android代碼檢查規(guī)則Lint的自定義與應(yīng)用詳解
本文主要介紹了Android代碼檢查規(guī)則Lint的自定義與應(yīng)用詳解,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04
Android中獲得正在運(yùn)行的程序和系統(tǒng)服務(wù)的方法
這篇文章主要介紹了Android中獲得正在運(yùn)行的程序和系統(tǒng)服務(wù)的方法,分別是對ActivityManager.RunningAppProcessInfo類和ActivityManager.RunningServiceInfo類的使用,需要的朋友可以參考下2016-02-02
Android控件AppWidgetProvider使用方法詳解
這篇文章主要為大家詳細(xì)介紹了Android控件AppWidgetProvider的使用方法詳解,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08
Android中RecyclerView實(shí)現(xiàn)簡單購物車功能
這篇文章主要為大家詳細(xì)介紹了Android中RecyclerView實(shí)現(xiàn)簡單購物車功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02
Android 實(shí)現(xiàn)監(jiān)聽的四種方法詳解實(shí)例代碼
這篇文章主要介紹了Android 實(shí)現(xiàn)監(jiān)聽的方法詳解實(shí)例代碼的相關(guān)資料,這里整理了四種方法,需要的朋友可以參考下2016-10-10

