讀古今文學網 > Android程序設計:第2版 > Google Maps Activity >

Google Maps Activity

集成在Android中的應用中就有Google Maps應用。在應用中啟動Google Maps的方式和從其他Activity啟動的方式相同:

1.創建Intent(new Intent(String action,Uri uri)),表明你要顯示地圖。其參數是:

·Action參數,必須指定為ACTION_VIEW。

·Uri參數,必須指定以下其中一種URI機制來替換你的數據:

─geo:latitude, longitude

─geo: latitude , longitude ?z= zoom

─geo:0,0?q my_street_address

─geo:0,0?q business_near_city

2.調用startActivity(Intent intent),使用剛創建的intent。

創建地圖的一個示例如下:


      Intent intent = new Intent(ACTION_VIEW, "geo:37.422006,-122.084095");
      startActivity(intent);
  

這顯然很簡單,而且它使你能夠使用功能強大的Google Maps,但是這種簡單的方式還不能做到把地圖集成到你的應用中。Google Maps本身就是應用,你無法改變其用戶界面,也無法在地圖上添加圖形。Android為了讓普通應用能夠方便地基於Google Maps進行二次開發而專門提供了更靈活的包。