<?xml version="1.0" encoding="utf-8"?>
<!-- This file is /res/layout/mapview.xml -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:id="@+id/zoomin" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="+"
android:onClick="myClickHandler" android:padding="12px" />
<Button android:id="@+id/zoomout" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="-"
android:onClick="myClickHandler" android:padding="12px" />
<Button android:id="@+id/sat" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Satellite"
android:onClick="myClickHandler" android:padding="8px" />
<Button android:id="@+id/street" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Street"
android:onClick="myClickHandler" android:padding="8px" />
<Button android:id="@+id/traffic" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Traffic"
android:onClick="myClickHandler" android:padding="8px" />
<Button android:id="@+id/normal" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Normal"
android:onClick="myClickHandler" android:padding="8px" />
</LinearLayout>
<com.google.android.maps.MapView
android:id="@+id/mapview" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:clickable="true"
android:apiKey="XXXXXXXXXXXXXXXXXXXXXXXXXX" />
</LinearLayout>
The main activity:
package com.mvda;
// This file is MapViewDemoActivity.java
import android.os.Bundle;
import android.view.View;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
public class MapViewDemoActivity extends MapActivity
{
private MapView mapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapview);
mapView = (MapView)findViewById(R.id.mapview);
}
public void myClickHandler(View target) {
switch(target.getId()) {
case R.id.zoomin:
mapView.getController().zoomIn();
break;
case R.id.zoomout:
mapView.getController().zoomOut();
break;
case R.id.sat:
mapView.setSatellite(true);
break;
case R.id.street:
mapView.setStreetView(true);
break;
case R.id.traffic:
mapView.setTraffic(true);
break;
case R.id.normal:
mapView.setSatellite(false);
mapView.setStreetView(false);
mapView.setTraffic(false);
break;
}
}
@Override
protected boolean isLocationDisplayed() {
return false;
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}