简体   繁体   English

根据存储在SQLite中的坐标创建地理点-Android

[英]Create geopoints from coordinates stored in SQLite - Android

I have a database with coordinates stored and I would like to have these read and automatically populated on a map. 我有一个存储坐标的数据库,我想读取这些坐标并将其自动填充到地图上。 I've tried several attempts but cannot seem to get this to work. 我尝试了几次尝试,但似乎无法使它正常工作。 Here is my code: 这是我的代码:

public class allmapactivity extends MapActivity {
MapController mControl;
GeoPoint GeoP;
MapView mapV;
private SQLiteAdapter mySQLiteAdapter;
Cursor cursor;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);


    mapV = (MapView) findViewById(R.id.mapview);
    mapV.displayZoomControls(true);
    mapV.setBuiltInZoomControls(true);
    mapV.setSatellite(false);

    List<Overlay> mapOverlays = mapV.getOverlays();
    Drawable drawable = this.getResources().getDrawable(R.drawable.pin);
    HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable, this);

    cursor = mySQLiteAdapter.queueAll5();
    cursor.moveToFirst();

    while (cursor.isAfterLast() == false) {
        GeoPoint point = new GeoPoint((int) (cursor.getInt(cursor.getColumnIndex(SQLiteAdapter.KEY_CONTENT11))*1E6), (int) (cursor.getInt(cursor.getColumnIndex(SQLiteAdapter.KEY_CONTENT12))*1E6));
        OverlayItem overlayitem = new OverlayItem(point, "Test", "Test");
        itemizedoverlay.addOverlay(overlayitem);
        mapOverlays.add(itemizedoverlay);
    cursor.moveToNext();
}



}


@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}

}

If ANYBODY can tell me why this doesn't work I'd be grateful! 如果ANYBODY可以告诉我为什么这不起作用,我将不胜感激! PS here is the logcat: PS这里是logcat:

07-19 07:27:14.193: E/AndroidRuntime(531): FATAL EXCEPTION: main
07-19 07:27:14.193: E/AndroidRuntime(531): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.inh.mapbud/com.inh.mapbud.allmapactivity}: java.lang.NullPointerException
07-19 07:27:14.193: E/AndroidRuntime(531):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
07-19 07:27:14.193: E/AndroidRuntime(531):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
07-19 07:27:14.193: E/AndroidRuntime(531):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-19 07:27:14.193: E/AndroidRuntime(531):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
07-19 07:27:14.193: E/AndroidRuntime(531):  at android.os.Handler.dispatchMessage(Handler.java:99)
07-19 07:27:14.193: E/AndroidRuntime(531):  at android.os.Looper.loop(Looper.java:130)
07-19 07:27:14.193: E/AndroidRuntime(531):  at android.app.ActivityThread.main(ActivityThread.java:3683)
07-19 07:27:14.193: E/AndroidRuntime(531):  at java.lang.reflect.Method.invokeNative(Native Method)
07-19 07:27:14.193: E/AndroidRuntime(531):  at java.lang.reflect.Method.invoke(Method.java:507)
07-19 07:27:14.193: E/AndroidRuntime(531):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-19 07:27:14.193: E/AndroidRuntime(531):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-19 07:27:14.193: E/AndroidRuntime(531):  at dalvik.system.NativeStart.main(Native Method)
07-19 07:27:14.193: E/AndroidRuntime(531): Caused by: java.lang.NullPointerException
07-19 07:27:14.193: E/AndroidRuntime(531):  at com.inh.mapbud.allmapactivity.onCreate(allmapactivity.java:45)
07-19 07:27:14.193: E/AndroidRuntime(531):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-19 07:27:14.193: E/AndroidRuntime(531):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
07-19 07:27:14.193: E/AndroidRuntime(531):  ... 11 more

检查allmapactivity活动的第45行。

Try to move this line 尝试移动这条线

mapOverlays.add(itemizedoverlay);

outside your loop, it seems as you are looping again and again for each entry. 在循环之外,似乎您一次又一次地为每个条目循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM