Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/385.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.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
Java 如何存储地图坐标并检索它们_Java_Android_Eclipse - Fatal编程技术网

Java 如何存储地图坐标并检索它们

Java 如何存储地图坐标并检索它们,java,android,eclipse,Java,Android,Eclipse,我有100个地图坐标,我计划存储在5个xml中,如何将它们存储在xml中并在代码中检索它们 MapView mapView; MapController mc; GeoPoint p; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

我有100个地图坐标,我计划存储在5个xml中,如何将它们存储在xml中并在代码中检索它们

MapView mapView; 
MapController mc;
GeoPoint p;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map1);

    mapView = (MapView) findViewById(R.id.mapView);
    new LinearLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT); 
    mapView.displayZoomControls(true);

    mc = mapView.getController();
    String coordinates[] = {" 53.804224", "-1.759057"};
    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); 
    mapView.invalidate();
}

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

如果要将这些数据存储在XML中,则需要有一个定义元素和属性的DTD,然后是一个写入这些元素和属性的方法。您通常会使用经过良好测试的库,而不是使用自己的库。您需要确定是以串行方式还是随机方式访问数据SAX或DOM

Sun在这方面有很好的Java示例

以下是一些关于XML的介绍材料:

IBM Developerworks:


如果您没有XML的特定需求,那么可以考虑更简单的可互换数据文件,例如,和. 在csv逗号分隔值文件/列表中存储坐标似乎是开销最低的最简单方法。只要您只真正存储long/lat坐标

我会避免将它们存储在XML文件中,除非您有很好的理由,比如从服务器发送/获取XML文件,因为解析XML文件比简单的csv文件(即简单的拆分/连接操作)造成更大的开销


但是,如果坐标是动态的,由用户添加,并且经常更改,并且可以有比最初的100对更多的坐标对,那么sqlite数据库将是一种更好的方法

为什么不使用sqlite数据库?
xml is a marked language with many forms (title,head,content,sub-item).
But your current data doesn't have such style.
I suppose you'd better store them into binary files in a custom form as following:
234.34 4535.435
3455.24 3554.356
235.234 45435.46
...............
you could access them in char,then translate into double.
moreover,SQLiteDatabase is an alternative.