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.
MapView mapView;
MapController mc;
GeoPoint p;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.l开发者_运维问答ayout.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. 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)
Sun has good Java examples at SDN
Here is some good intro material on XML:
IBM Developerworks:
Introduction to XML
C/C++ developers: Fill your XML toolbox
If you do not have a specific NEED for XML, there are much simpler interchangeable data files to consider, such as JSON and YAML.
Storing the coordinates in a csv (comma-seprated values) file/list seems to be the easiest way with lowest overhead. 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.
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
精彩评论