简体   繁体   English

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

[英]How can I store map coordinates and retrieve them

I have 100 map coordinates which I plan to store in 5 xml,s, how can I store them in a xml and retrive them in this code. 我有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;
}

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.

If you are storing this data in XML, you need to have a DTD that defines the elements and attributes and then a method to write those elements and attributes. 如果以XML格式存储此数据,则需要具有定义元素和属性的DTD,然后是编写这些元素和属性的方法。 You would usually use a well tested library rather than rolling your own. 通常,您会使用经过良好测试的库,而不是自己滚动库。 You need to determine if you are going to access your data serially or randomly (SAX or DOM) 您需要确定是要串行访问还是随机访问数据(SAX或DOM)

Sun has good Java examples at SDN Sun在SDN上有很好的Java示例

Here is some good intro material on XML: 这是有关XML的一些很好的入门资料:

IBM Developerworks: IBM Developerworks:

Introduction to XML XML简介

C/C++ developers: Fill your XML toolbox C / C ++开发人员:填充您的XML工具箱

If you do not have a specific NEED for XML, there are much simpler interchangeable data files to consider, such as JSON and YAML . 如果您没有针对XML的特定NEED,则需要考虑更简单的可互换数据文件,例如JSONYAML

Storing the coordinates in a csv (comma-seprated values) file/list seems to be the easiest way with lowest overhead. 将坐标存储在csv(逗号分隔值)文件/列表中似乎是开销最小的最简单方法。 As long you're only really storing the long/lat coordinates. 只要您只真正存储长/纬度坐标。

I'd avoid storing them in XML files, unless you have a good reason for it, like senting/fetching it from a server, as parsing XML files causes bigger overhead than simple csv files, which is simple split/join operations. 我会避免将它们存储在XML文件中,除非您有充分的理由,例如从服务器发送/获取它,因为解析XML文件比简单的csv文件(简单的拆分/合并操作)会产生更大的开销。

However, if the coordinates are dynamic and added by the user and change often and there can be more pairs of coordinates than that initial 100, a sqlite database would be a better way to go 但是,如果坐标是动态的并且由用户添加并且经常更改,并且可能有比初始的100对更多的坐标对,那么使用sqlite数据库将是更好的选择

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

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