3 つの主要なアクティビティ (アクティビティ 1、2、3 と呼びましょう) を含むプロジェクトを作成しています。アクティビティ 1 では、バンドル エクストラで番号を渡します。
newActivity.putExtra("LAT", getText(R.string.LAT1));
newActivity.putExtra("LNG", getText(R.string.LNG1));
次に、2番目のもので、私はこれを次のように取得します:
double Lata;
double Lnga;
//in onCreate..
Bundle extras = getIntent().getExtras();
Lata = extras.getDouble("LAT");
Lnga = extras.getDouble("LNG");
そして、次のように 3 番目のアクティビティに渡します。
newActivity.putExtra("LAT",Lata);
newActivity.putExtra("LNG",Lnga);
最後に、3 番目のアクティビティでは:
public class mapview extends MapActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.map);
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
//mapView.setSatellite(true);
//mapView.setStreetView(true);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.pin);
HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable,this);
Bundle extras = getIntent().getExtras();
final double Latc = extras.getDouble("LAT");
final double Lngc = extras.getDouble("LNG");
Integer txt_map = extras.getInt("MAP_NAME");
TextView mapname=(TextView)findViewById(R.id.museum_address_name);
mapname.setText(getText(txt_map));
Double lat = Double.valueOf(Latc*1E6);
Double lng = Double.valueOf(Lngc*1E6);
//---------------------------------------------------
GeoPoint center = new GeoPoint(Double.valueOf(Latc*1E6).intValue(), Double.valueOf(Lngc*1E6).intValue());
MapController controller = mapView.getController();
controller.setCenter(center);
controller.setZoom(15);
//---------------------------------------------------
GeoPoint point = new GeoPoint(lat.intValue(), lng.intValue());
OverlayItem overlayitem = new OverlayItem(point, "", "");
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
}
@Override
protected boolean isRouteDisplayed()
{
return false;
}
}
結果は南アメリカのどこかですが、私の緯度と経度はヨーロッパにあります..何が間違っているのですか?2時間以上修正しようとしています...:(
編集
04-25 23:58:19.001: W/KeyCharacterMap(3746): No keyboard for id 0
04-25 23:58:19.081: W/KeyCharacterMap(3746): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
04-25 23:58:22.461: W/Bundle(3746): Key LAT expected Double but value was a java.lang.Integer. The default value 0.0 was returned.
04-25 23:58:22.481: W/Bundle(3746): Attempt to cast generated internal exception:
04-25 23:58:22.481: W/Bundle(3746): java.lang.ClassCastException: java.lang.Integer
04-25 23:58:22.481: W/Bundle(3746): at android.os.Bundle.getDouble(Bundle.java:1017)
04-25 23:58:22.481: W/Bundle(3746): at android.os.Bundle.getDouble(Bundle.java:1000)
04-25 23:58:22.481: W/Bundle(3746): at kostas.menu.athensmuseums.museum_item.onCreate(museum_item.java:39)
04-25 23:58:22.481: W/Bundle(3746): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-25 23:58:22.481: W/Bundle(3746): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-25 23:58:22.481: W/Bundle(3746): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-25 23:58:22.481: W/Bundle(3746): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-25 23:58:22.481: W/Bundle(3746): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-25 23:58:22.481: W/Bundle(3746): at android.os.Handler.dispatchMessage(Handler.java:99)
04-25 23:58:22.481: W/Bundle(3746): at android.os.Looper.loop(Looper.java:123)
04-25 23:58:22.481: W/Bundle(3746): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-25 23:58:22.481: W/Bundle(3746): at java.lang.reflect.Method.invokeNative(Native Method)
04-25 23:58:22.481: W/Bundle(3746): at java.lang.reflect.Method.invoke(Method.java:521)
04-25 23:58:22.481: W/Bundle(3746): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-25 23:58:22.481: W/Bundle(3746): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-25 23:58:22.481: W/Bundle(3746): at dalvik.system.NativeStart.main(Native Method)
04-25 23:58:22.481: W/Bundle(3746): Key LNG expected Double but value was a java.lang.Integer. The default value 0.0 was returned.
04-25 23:58:22.491: W/Bundle(3746): Attempt to cast generated internal exception:
04-25 23:58:22.491: W/Bundle(3746): java.lang.ClassCastException: java.lang.Integer
04-25 23:58:22.491: W/Bundle(3746): at android.os.Bundle.getDouble(Bundle.java:1017)
04-25 23:58:22.491: W/Bundle(3746): at android.os.Bundle.getDouble(Bundle.java:1000)
04-25 23:58:22.491: W/Bundle(3746): at kostas.menu.athensmuseums.museum_item.onCreate(museum_item.java:40)
04-25 23:58:22.491: W/Bundle(3746): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-25 23:58:22.491: W/Bundle(3746): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-25 23:58:22.491: W/Bundle(3746): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-25 23:58:22.491: W/Bundle(3746): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-25 23:58:22.491: W/Bundle(3746): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-25 23:58:22.491: W/Bundle(3746): at android.os.Handler.dispatchMessage(Handler.java:99)
04-25 23:58:22.491: W/Bundle(3746): at android.os.Looper.loop(Looper.java:123)
04-25 23:58:22.491: W/Bundle(3746): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-25 23:58:22.491: W/Bundle(3746): at java.lang.reflect.Method.invokeNative(Native Method)
04-25 23:58:22.491: W/Bundle(3746): at java.lang.reflect.Method.invoke(Method.java:521)
04-25 23:58:22.491: W/Bundle(3746): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-25 23:58:22.491: W/Bundle(3746): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-25 23:58:22.491: W/Bundle(3746): at dalvik.system.NativeStart.main(Native Method)
04-25 23:58:24.251: W/MapActivity(3746): Recycling dispatcher com.google.googlenav.datarequest.DataRequestDispatcher@44ec4318