自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Android開發(fā)GoogleMap入門

移動開發(fā) Android
開發(fā)基于谷歌地圖的應(yīng)用和普通的android應(yīng)用差不多都要使用它提供給我們的類庫,所不同的是google map的類庫不是android平臺的基本類庫,是google api的一部分,所以建立項目時,SDK要選擇Google APIs;還有一點,開發(fā)基于地圖的應(yīng)用時候需要使用google map的APIkey,必須先申請key,然后才能開發(fā)基于地圖的應(yīng)用。

Android開發(fā)要連接GoogelMaps使用MapView時需要,先從Google網(wǎng)站申請一組經(jīng)過驗證的Maps API Key授權(quán)碼,這個在網(wǎng)上很多。

[代碼] [Java]代碼

  1. package com.android.antking.map; 
  2.     import com.google.android.maps.MapActivity; 
  3.     import com.google.android.maps.GeoPoint; 
  4.     import com.google.android.maps.MapController; 
  5.     import com.google.android.maps.MapView; 
  6.     import android.os.Bundle; 
  7.     public class MyMain extends MapActivity { 
  8.         //放大倍數(shù) 
  9.        static final int  INITIAL_ZOOM_LEVEL=12
  10.        //中心點 
  11.        static final int  INITIAL_LATITUDE=123465465
  12.        static final int  INITIAL_LONGITUDR=15634646
  13.         public void onCreate(Bundle savedInstanceState) { 
  14.             super.onCreate(savedInstanceState); 
  15.             setContentView(R.layout.main); 
  16.             MapView mapView = (MapView) findViewById(R.id.mapView); 
  17.             //enable to change the size of the map 
  18.             mapView.setBuiltInZoomControls(true); 
  19.             //設(shè)置Zoom 大小和地圖的中心點 
  20.             MapController mc = mapView.getController(); 
  21.             mc.setZoom(INITIAL_ZOOM_LEVEL); 
  22.             mc.setCenter(new GeoPoint(INITIAL_LATITUDE,INITIAL_LONGITUDR)); 
  23.         } 
  24.         @Override 
  25.         protected boolean isRouteDisplayed() { 
  26.             // TODO Auto-generated method stub 
  27.             return false
  28.         } 
  29.     } 

[代碼] [XML]代碼

  1. <?xml version="1.0" encoding="utf-8"?> 
  2.     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  3.         android:orientation="vertical" 
  4.         android:layout_width="fill_parent" 
  5.         android:layout_height="fill_parent" 
  6.         > 
  7.     <TextView  
  8.         android:layout_width="fill_parent" 
  9.         android:layout_height="wrap_content" 
  10.         android:text="@string/hello" 
  11.         /> 
  12.      <com.google.android.maps.MapView 
  13.           android:id="@+id/mapView" 
  14.           android:layout_width="fill_parent" 
  15.           android:layout_height="fill_parent" 
  16.           android:enabled="true" 
  17.           android:clickable="true" 
  18.           android:apiKey="0FZLYf-YM4SRrJrJum55MeeaO4Gd_IitVFmtUeA"/>這個是自己開發(fā)的google mapApi 密鑰 
  19.     </LinearLayout> 

[代碼] 在這里加上google的地圖包,還有Internet權(quán)限

  1. <?xml version="1.0" encoding="utf-8"?> 
  2.     <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
  3.           package="com.android.antking.map" 
  4.           android:versionCode="1" 
  5.           android:versionName="1.0"
  6.         <uses-sdk android:minSdkVersion="7" /> 
  7.         <uses-permission android:name="android.permission.INTERNET"></uses-permission> 
  8.         <application android:icon="@drawable/icon" android:label="@string/app_name"
  9.             <activity android:name=".MyMain" 
  10.                       android:label="@string/app_name"
  11.                 <intent-filter> 
  12.                     <action android:name="android.intent.action.MAIN" /> 
  13.                     <category android:name="android.intent.category.LAUNCHER" /> 
  14.                 </intent-filter> 
  15.             </activity> 
  16.             <uses-library android:name="com.google.android.maps"></uses-library> 
  17.         </application> 
  18.     </manifest> 

1.創(chuàng)建工程,注意SDK旋轉(zhuǎn)為"Goolge APIs”

2.修改AndroidManifest.xml文件

由于使用Google Map API,所以必須添加<uses-library android:name="com.google.android.maps" />

由于需要從網(wǎng)絡(luò)獲取地圖數(shù)據(jù),所以需要訪問網(wǎng)絡(luò)的權(quán)限<uses-permission android:name="android.permission.INTERNET"/>

可能還需要添加其他權(quán)限。

3.創(chuàng)建MapView

4.實現(xiàn)MapActivity

5.MapController的使用

6.Ovelay的使用

責(zé)任編輯:閆佳明 來源: oschina
相關(guān)推薦

2011-09-09 14:09:17

Android Wid

2013-01-16 14:41:14

Android開發(fā)Android SDK

2013-01-16 15:07:30

Android NDKAndroid開發(fā)

2010-02-06 15:31:18

ibmdwAndroid

2009-07-22 14:55:16

ibmdwAndroid

2013-01-10 13:50:25

Android開發(fā)組件

2010-02-04 17:59:50

Android SDK

2009-03-11 13:18:57

Android入門Android開發(fā)Android模擬器

2013-05-20 15:42:22

2013-01-16 17:34:32

Android開發(fā)路線圖

2012-04-26 22:57:57

Android

2013-01-17 16:17:33

Android開發(fā)Intent組件

2017-04-10 15:47:50

Android Stujni開發(fā)入門

2013-01-10 14:21:24

Android開發(fā)組件Activities

2014-05-08 13:36:07

Android Wea開發(fā)者預(yù)覽版

2017-11-27 13:09:00

AndroidGradle代碼

2013-01-17 15:51:42

Android開發(fā)應(yīng)用程序組件

2010-08-26 08:57:04

AndroidAndroid開發(fā)

2012-01-10 09:56:32

WPF

2024-07-01 09:08:00

點贊
收藏

51CTO技術(shù)棧公眾號