Question

I know this type of question has been asked before but I cannot find an answer for my issue. And the answers to my previous question unfortunately don't work I have an xml file which stores LatLng values and an icon name for markers which I want to be displayed on a map. The map works, but I cannot seem to get the code for the xml to work

This is my XML

<?xml version="1.0"?>
<markers>
<marker>
<lat>51.500906</lat>
<lng>-0.124433</lng>
<icon>landmark</icon>
</marker>
</markers>

And this is my code that I am using (should I be creating a new class file or adding a class to my MainActivity class)?

InputStream in = this.getResources().openRawResource(R.raw.fileName);

DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dfactory.newDocumentBuilder();
Document doc = db.parse(in, null);

NodeList markers = doc.getElementsByTagName("marker");

for (int i = 0; i < markers.getLength(); i++){
Element item = (Element) markers.item(i);
String stringLat = item.getAttribute("lat");
String stingLng = item.getAttribute("lng");
String icon = item.getAttribute("icon");
Double lat = Double.valueOf(stringLat);
Double lng = Double.valueOf(stringlng);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.the_map)).getMap();

map.addMarker(new MarkerOptions)
.position(new LatLng(lat, lng)) 

.icon(BitmapDescriptorFactory.fromResource(getResources().getIdentifier(icon, "drawable", getPackageName()));

In the above code I get errors for the Document doc line and the .getAttribute lines as well as the .position line, all other lines do not bring up errors in Eclipse

Please advise

Thanks

Was it helpful?

Solution

It sounds like you are missing an import for the Document class? Is there an "import org.w3c.dom.Document;" in your imports at the top of the code?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top