首先先更改XML描述檔
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<com.google.android.maps.MapView
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey=""
android:clickable="true" />
<LinearLayout android:id="@+id/draw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
>
</LinearLayout>
</RelativeLayout>
※android:alignParentBottom 如果該值為true,則將該控制項的底部和父控制項的底部對齊
※android:layout_centerHorizontal 如果為真,該控制項將被至於水準方向的中央
package com.demo.android.MapA;
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;
import android.view.ViewGroup;
public class MapAActivity extends MapActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViews();
setupMap();
}
private MapView mv;//宣告googleMap物件
private MapController mc;//宣告googleMap控制物件
private ViewGroup vg;//宣告縮放控制物件
private void setupMap() {
// TODO Auto-generated method stub
GeoPoint point_pingtung=new GeoPoint((int)(22.669306*1E6),((int)(120.486203*1E6)));//設定地圖座標經度及緯度
mv.setTraffic(true);//地圖檢視模式
mc.setZoom(17);//值為1-256
mc.animateTo(point_pingtung);//顯示給定的點
}
@SuppressWarnings("deprecation")
private void findViews() {
// TODO Auto-generated method stub
mv=(MapView)findViewById(R.id.map);//抓取google map物件
mc=mv.getController();//控制map物件
vg=(ViewGroup)findViewById(R.id.draw);//載入LinerLayout
mv.setBuiltInZoomControls(true);//加入縮放控制到LinerLayout
//vg.addView(mv.getZoomControls());//加入縮放控制到LinerLayout(1.5版\後不建議使用)
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}

沒有留言:
張貼留言