申請googleMap服務並且顯示地圖(基礎篇)

來源:互聯網
上載者:User

我會按照先後順序寫出來,包括原始碼

1.開啟命令列方式,找到debug.keystore檔案

注意:使用android開發一年以上,keystore檔案將失效,帶來的問題是模擬器無法自動產生apk檔案,解決方案是刪除此檔案,重新啟動eclipse就OK了。

輸入指令:cd .android斷行符號

然後輸入keytool -list -alias androiddebugkey -keystore debug.keystore -v(千萬不要輸錯奧)

接下來要你輸入密鑰庫口令,輸入android就行了,詳細的如

然後把MD5記下來,準備申請google api key

2.申請google api key

開啟下面這個網址https://developers.google.com/android/maps-api-signup?hl=zh-CN

然後輸入你的MD5,然後就會得到google api key 了

然後就可以進行下面了。

說來也奇怪,我第一次申請的時候,頁面總是不能完全開啟,我就找了好多翻牆軟體,結果也不行,不知道為什麼總是得不到,但是後來過了幾天,就可以申請了,這真是個問題,有機會大家可以給我說說這事為什嗎?奇怪了。

解決辦法:在C:\Windows\System32\drivers\etc下面找到host檔案,在檔案最後添加203.208.46.180     google-developers.appspot.com重啟瀏覽器登入這個網址就OK了。

好,不扯淡了,繼續下面的

3.建立android項目,注意要建立的項目是在google api 上建立的,相信大家都知道,建立工程的時候注意一下就行了,這裡就不出圖了。

4.下面就是我建立的工程的代碼,非常簡單,只是為了測試使用,不能放大縮小,只能顯示地圖,代碼如下

這個是manifest.xml檔案,需要註冊連網,以及使用googlemap的庫(library)

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="mars.com"    android:versionCode="1"    android:versionName="1.0" >    <uses-sdk android:minSdkVersion="10" />    <uses-permission android:name="android.permission.INTERNET" />    <application        android:icon="@drawable/ic_launcher"        android:label="@string/app_name" >        <activity            android:name=".GoogleMapDemoActivity"            android:label="@string/app_name" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>        <uses-library android:name="com.google.android.maps" />    </application></manifest>

main.xml檔案如下,就不多解釋了,上面有圖,就照著官網的弄就行了。

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <com.google.android.maps.MapView        android:id="@+id/mapview"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:apiKey="0aVeWdF7g8mo7Q-S3rDHcpmANgEF9752OHJlh0g"        android:clickable="true"        android:state_enabled="true" /></LinearLayout>

activity檔案如下

package mars.com;import android.os.Bundle;import com.google.android.maps.MapActivity;public class GoogleMapDemoActivity extends MapActivity {@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);}@Overrideprotected boolean isRouteDisplayed() {//是否導航return false;//不導航}}

注意,是MapActivity千萬別寫錯。。。好,今天到此為止

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.