这是我的代码,我正在尝试显示坐标,这里我正在寻找左上角和右下角的长度&纬度值,但它不工作任何人建议我任何修改或任何其他方法来获得坐标..
public class GpsoverlayActivity extends MapActivity {
/** Called when the activity is first created. */
MapView map;
MapController mc;
GeoPoint gp;
//Projection projection ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
map=(MapView)findViewById(R.id.mapView);
mc=map.getController();
mc.setCenter(gp);
mc.setZoom(20);
Projection proj = map.getProjection();
GeoPoint topLeft = proj.fromPixels(0, 0);
GeoPoint bottomRight = proj.fromPixels(map.getWidth()-1, map.getHeight()-1);
Double topLat = topLeft.getLatitudeE6()/1E6;
Double topLon = topLeft.getLongitudeE6()/1E6;
Double bottomLat = bottomRight.getLatitudeE6()/1E6;
Double bottomLon = bottomRight.getLongitudeE6()/1E6;
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
myLocationOverlay.enableMyLocation();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
myLocationOverlay.disableMyLocation();
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
这是我的LOgCat
12-23 11:26:50.264: W/dalvikvm(390): Unable to resolve superclass of Lcom/gpsoverlay/emigos/GpsoverlayActivity; (6)
12-23 11:26:50.264: W/dalvikvm(390): Link of class 'Lcom/gpsoverlay/emigos/GpsoverlayActivity;' failed
12-23 11:26:50.275: D/AndroidRuntime(390): Shutting down VM
12-23 11:26:50.285: W/dalvikvm(390): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
12-23 11:26:50.285: E/AndroidRuntime(390): Uncaught handler: thread main exiting due to uncaught exception
12-23 11:26:50.456: E/AndroidRuntime(390): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.gpsoverlay.emigos/com.gpsoverlay.emigos.GpsoverlayActivity}: java.lang.ClassNotFoundException: com.gpsoverlay.emigos.GpsoverlayActivity in loader dalvik.system.PathClassLoader@44e83900
12-23 11:26:50.456: E/AndroidRuntime(390): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
12-23 11:26:50.456: E/AndroidRuntime(390): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
12-23 11:26:50.456: E/AndroidRuntime(390): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
12-23 11:26:50.456: E/AndroidRuntime(390): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
12-23 11:26:50.456: E/AndroidRuntime(390): at android.os.Handler.dispatchMessage(Handler.java:99)
12-23 11:26:50.456: E/AndroidRuntime(390): at android.os.Looper.loop(Looper.java:123)
12-23 11:26:50.456: E/AndroidRuntime(390): at android.app.ActivityThread.main(ActivityThread.java:4363)
12-23 11:26:50.456: E/AndroidRuntime(390): at java.lang.reflect.Method.invokeNative(Native Method)
12-23 11:26:50.456: E/AndroidRuntime(390): at java.lang.reflect.Method.invoke(Method.java:521)
12-23 11:26:50.456: E/AndroidRuntime(390): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
12-23 11:26:50.456: E/AndroidRuntime(390): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12-23 11:26:50.456: E/AndroidRuntime(390): at dalvik.system.NativeStart.main(Native Method)
12-23 11:26:50.456: E/AndroidRuntime(390): Caused by: java.lang.ClassNotFoundException: com.gpsoverlay.emigos.GpsoverlayActivity in loader dalvik.system.PathClassLoader@44e83900
12-23 11:26:50.456: E/AndroidRuntime(390): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
12-23 11:26:50.456: E/AndroidRuntime(390): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
12-23 11:26:50.456: E/AndroidRuntime(390): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
12-23 11:26:50.456: E/AndroidRuntime(390): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
12-23 11:26:50.456: E/AndroidRuntime(390): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
12-23 11:26:50.456: E/AndroidRuntime(390): ... 11 more
12-23 11:26:50.645: I/dalvikvm(390): threadid=7: reacting to signal 3
12-23 11:26:50.825: I/dalvikvm(390): Wrote stack trace to '/data/anr/traces.txt'
12-23 11:26:54.515: I/Process(390): Sending signal. PID: 390 SIG: 9
答案 0 :(得分:0)
您需要扩展MapActivity而不是Activity。地图的所有类和接口都可用于MapActivity,MapView只能在MapActivity中使用。
在叠加初始化之后,您使用的是mapv对象,我没有找到这个。
myLocationOverlay = new MyLocationOverlay(this, mapv); // here mapv object used instead of map I think
mapv.getOverlays().add(myLocationOverlay);
mapv.postInvalidate();