我有100个地图坐标,我计划以5 xml存储,s,如何将它们存储在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;
}
答案 0 :(得分:0)
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.
答案 1 :(得分:0)
如果要将此数据存储在XML中,则需要具有定义元素和属性的DTD,然后使用方法来编写这些元素和属性。您通常会使用经过良好测试的库而不是自己编写库。您需要确定是要串行还是随机访问数据(SAX或DOM)
Sun在SDN
上有很好的Java示例以下是关于XML的一些很好的介绍材料:
IBM Developerworks:
答案 2 :(得分:0)
将坐标存储在csv(逗号分隔值)文件/列表中似乎是开销最低的最简单方法。只要您真正存储长/纬坐标。
我要避免将它们存储在XML文件中,除非你有充分的理由,比如从服务器发送/获取它,因为解析XML文件会导致比简单的csv文件更大的开销,这是简单的分割/连接操作。
但是,如果坐标是动态的并且由用户添加并经常更改,并且可以有比初始100更多的坐标对,那么sqlite数据库将是更好的方法