IamHereの全ソースコードです。
長さに制限があるとは・・・知らなかった(^_^;)
package com.google.android.iamhere;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Point;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.Menu;
public class IamHere extends MapActivity {
private MapView mapView;
private static final int M_ZOOMIN = 1;
private static final int M_ZOOMOUT = 2;
private static final int M_CHANGE_MODE = 3;
private static final int M_I_AM_HERE = 4;
private static final int M_TOKYO_TOWER = 5;
private static final int M_NAGOYA = 6;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// マップを制御するために、マップビューとコントローラを生成する
mapView = new MapView(this);
setContentView(mapView);
}
// メニューボタンが押下されたときの処理
// メニューにアイテムを追加する
@Override
public boolean onCreateOptionsMenu(Menu menu) {
boolean supRetVal = super.onCreateOptionsMenu(menu);
menu.add(0, M_ZOOMIN, "ズーーームイン");
menu.add(0, M_ZOOMOUT, "ズーーーームアウト!!!");
menu.add(0, M_CHANGE_MODE, "表示モード変更");
menu.add(0, M_I_AM_HERE, "私はここよ!!!");
menu.add(0, M_TOKYO_TOWER, "東京タワーを見てみよう!!!");
menu.add(0, M_NAGOYA, "名古屋城ってどこだ!!");
return supRetVal;
}
// メニューのアイテムが選択された時の処理
@Override
public boolean onOptionsItemSelected(Menu.Item item) {
Double ido = 0.0;
Double keido = 0.0;
switch (item.getId()) {
case M_ZOOMIN:
mapView.getController().zoomTo(Math.min(20, mapView.getZoomLevel() + 1));
return true;
case M_ZOOMOUT:
mapView.getController().zoomTo(Math.max(1, mapView.getZoomLevel() - 1));
return true;
case M_CHANGE_MODE:
mapView.toggleSatellite();
return true;
case M_I_AM_HERE:
// 自分の居る位置(緯度、経度)を取得する
LocationManager locationManager = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
Location location = locationManager.getCurrentLocation("gps");
ido = location.getLatitude() * 1E6;
keido = location.getLongitude() * 1E6;
MapController mapController = this.mapView.getController();
mapController.centerMapTo(new Point(ido.intValue(), keido.intValue()), true);
return true;
case M_TOKYO_TOWER:
ido = 35.658632 * 1E6;
keido = 139.745411 * 1E6;
mapController = this.mapView.getController();
mapController.centerMapTo(new Point(ido.intValue(), keido.intValue()), true);
mapController.zoomTo(17);
if(!mapView.isSatellite()) {
mapView.toggleSatellite();
}
return true;
case M_NAGOYA:
ido = 35.185583 * 1E6;
keido = 136.899053 * 1E6;
mapController = this.mapView.getController();
mapController.centerMapTo(new Point(ido.intValue(), keido.intValue()), true);
mapController.zoomTo(17);
if(!mapView.isSatellite()) {
mapView.toggleSatellite();
}
return true;
}
return false;
}
}