MyMapActivity.java
package com.efolab.mapver1_1;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
public class MyMapActivity extends MapActivity implements LocationListener{
private final static String API_KEY = "KEY";
Context context;
LinearLayout base;
LinearLayout lHeader , lMain , lFooter;
LocationManager mLocationManager;
MapController mMapController;
TextView tv0 , tv1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = getApplicationContext();
base = new LinearLayout(context);
base.setOrientation(LinearLayout.VERTICAL);
setContentView(base);
lHeader = new LinearLayout(context);
lMain = new LinearLayout(context);
lFooter = new LinearLayout(context);
base.addView(lHeader);
base.addView(lMain , new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT , 0 , 1.0f));
base.addView(lFooter);
MapView mapView = new MapView(this , API_KEY); XXX
mapView.setEnabled(true);
mapView.setClickable(true);
tv0 = new TextView(context);
tv0.setText("HEADER");
tv1 = new TextView(context);
tv1.setText("FOOTER");
lHeader.addView(tv0);
lMain.addView(mapView);
lFooter.addView(tv1);
mMapController = mapView.getController();
mapView.getController().setZoom(20);
mapView.setBuiltInZoomControls(true);
mapView.invalidate();
mLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
}
@Override
protected void onResume() {
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER , 1000 , 1 , this);
super.onResume();
}
@Override
protected boolean isRouteDisplayed() {
TODO
return false;
}
public void onLocationChanged(Location location) {
GeoPoint gp = new GeoPoint((int)(location.getLatitude()*1E6) , (int)(location.getLongitude()*1E6));
double lat = gp.getLatitudeE6() / 1E6;
double lng = gp.getLongitudeE6() /1E6;
mMapController.animateTo(gp);
tv1.setText("緯度="+lat+",経度="+lng);
}
public void onProviderDisabled(String arg0) {
TODO
}
public void onProviderEnabled(String arg0) {
TODO
}
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
TODO
}
}
Manifest.xml
<manifest xmlnsandroid="http://schemas.android.com/apk/res/android"
package="com.efolab.mapver1_1"
androidversionCode="1"
androidversionName="1.0" >
<uses-sdk
androidminSdkVersion="10"
androidtargetSdkVersion="15" />
<uses-permission androidname="android.permission.INTERNET" />
<uses-permission androidname="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission androidname="android.permission.ACCESS_MOCK_LOCATION"/>
<application
androidicon="@drawable/ic_launcher"
androidlabel="@string/app_name"
androidtheme="@style/AppTheme" >
<activity androidname=".MyMapActivity" >
<intent-filter>
<action androidname="android.intent.action.MAIN" />
<category androidname="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library androidname="com.google.android.maps" />
</application>
</manifest>