Android Map Api (沒有Google Map 該怎麼辦!!???)

想要在Android APP 之中至入Google Map嗎?
只要照著下列的步驟
即可輕鬆地取得Google Map的服務

1) 取得Android Maps API 金鑰
請用下列網址申請
http://code.google.com/intl/zh-TW/android/maps-api-signup.html


2) 建立 Project




3) 修改 main.xml
res/layout/main.xml

 <?xml version="1.0" encoding="utf-8"?>  
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
   android:orientation="vertical"  
   android:layout_width="fill_parent"  
   android:layout_height="fill_parent"  
   >  
   <com.google.android.maps.MapView  
          android:layout_width="fill_parent"  
          android:layout_height="fill_parent"  
          android:apiKey="你/妳的金鑰"  
          android:id="@+id/mapView"   
          android:enabled="true"   
          android:clickable="true"/>  
 </RelativeLayout>  



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




5) 修改 GoogleMap.java
src/edu.android.googlemap/GoogleMap.java
 package edu.android.googlemap;  
 import com.google.android.maps.GeoPoint;  
 import com.google.android.maps.MapActivity;  
 import com.google.android.maps.MapController;  
 import com.google.android.maps.MapView;  
 import android.os.Bundle;  
 public class GoogleMap extends MapActivity {  
      MapController mControl;  
      GeoPoint geoPoint;  
      MapView mapView;  
      int latitude,longitude;  
   /** Called when the activity is first created. */  
   @Override  
   public void onCreate(Bundle savedInstanceState) {  
     super.onCreate(savedInstanceState);  
     setContentView(R.layout.main);  
     mapView =(MapView) findViewById(R.id.mapView);  
     mapView.displayZoomControls(true);  
     mapView.setBuiltInZoomControls(true);  
     longitude = (int) (121.30*1E6);         //E經  
     latitude = (int) (25.10*1E6);           //N緯   
     geoPoint = new GeoPoint(latitude,longitude);  
     mControl = mapView.getController();      
     mControl.setZoom(13);  
     mControl.animateTo(geoPoint);  
   }  
      @Override  
      protected boolean isRouteDisplayed() {  
           // TODO Auto-generated method stub  
           return false;  
      }  
 }  




6) 觀看結果

也可以加入電子羅盤至地圖


加入自訂所在位置圖片


使用 Google 位置圖形


沒有留言:

張貼留言