Android Map新用法:MapFragment應用

來源:互聯網
上載者:User

標籤:

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。代碼如下

<permissionandroid: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-featureandroid:glEsVersion="0x00020000"android:required="true"/> 

放在application聲明裡

<meta-dataandroid: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"/> 

 

Android Map新用法:MapFragment應用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.