Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何从sqlite数据库查询lat/long值并显示在Google地图上_Android_Sqlite_Google Maps - Fatal编程技术网

Android 如何从sqlite数据库查询lat/long值并显示在Google地图上

Android 如何从sqlite数据库查询lat/long值并显示在Google地图上,android,sqlite,google-maps,Android,Sqlite,Google Maps,如何从数据库中查询lat/long值并在该位置显示标记? 这是我的代码,设置lat/long时效果很好 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.branchmap); mapView = (MapView) findViewById(R.id.mapView1);

如何从数据库中查询lat/long值并在该位置显示标记? 这是我的代码,设置lat/long时效果很好

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.branchmap);
    mapView = (MapView) findViewById(R.id.mapView1);


      mc = mapView.getController();
          String[] coordinates = {"13.694317","100.601592"};
            double lat = Double.parseDouble(coordinates[0]);
            double lng = Double.parseDouble(coordinates[1]);

            p = new GeoPoint(
                    (int) (lat * 1E6), 
                    (int) (lng * 1E6));
            mc.animateTo(p);
            mc.setZoom(17); 


            mapOverlays = mapView.getOverlays();
            drawable = this.getResources().getDrawable(R.drawable.mark1);
            itemizedOverlay = new HelloItemizedOverlay(drawable);
            OverlayItem overlayitem = new OverlayItem(p, "", "");
            itemizedOverlay.addOverlay(overlayitem);
            mapOverlays.add(itemizedOverlay);
但是当我想查询它不起作用时,我应该把这部分代码放在哪里呢

try {
        ChannelDatabaseHelper dbHelper = new  ChannelDatabaseHelper(this.getApplicationContext());
        newDB = dbHelper.getWritableDatabase();
        Cursor c1 = newDB.rawQuery("SELECT lat,long FROM " +
                tableName , null);

        if (c1 != null ) {
            if  (c1.moveToFirst()) {
                do {

                    latitude =Integer.parseInt((c1.getString(c1.getColumnIndex("lat"))));
                    longitude = Integer.parseInt((c1.getString(c1.getColumnIndex("long"))));
                    p = new GeoPoint(
                            (int)(latitude *1E6 ), 
                            (int)(longitude *1E6 ));
                }while (c1.moveToNext());
            } 
        } 

请尝试以下代码

客户端应用程序是用什么编写的?很抱歉,我遗漏了这些信息,我正在使用android:使用overlay类并将图标设置为特定的检索点我刚刚添加了代码,上面的部分工作得很好,但是当我想从数据库中获取lat/long时,它根本不起作用-你需要更具体一些,而不是根本不起作用-你的应用程序会崩溃吗?例外情况?你有伪造的数据吗?您是否尝试记录您得到的输出?您是否确保DB看起来像您期望的那样?很难帮助你。
try {
        ChannelDatabaseHelper dbHelper = new  ChannelDatabaseHelper(this.getApplicationContext());
        newDB = dbHelper.getWritableDatabase();
        Cursor c1 = newDB.rawQuery("SELECT lat,long FROM " +
                tableName , null);

        if (c1 != null ) {
            if  (c1.moveToFirst()) {
                do {

                    latitude =Integer.parseDouble((c1.getString(c1.getColumnIndex("lat"))));
                    longitude = Integer.parseDouble((c1.getString(c1.getColumnIndex("long"))));
                    p = new GeoPoint(
                            (int)(latitude *1E6 ), 
                            (int)(longitude *1E6 ));
                    //Write a code to display this point on google-map
                }while (c1.moveToNext());
            } 
        }