Xml Parse ve Google Maps marker ekleme
Merhaba arkadaşlar
Elimde xml var içeri parse ettim fakat bunları marker olarak haritaya ekliyemiyorum acaba parse ederkenmi hata yapıyorum yardımcı olabilirmisiniz acaba.
<MAGAZALAR>
<MAGAZA>
<baslik>ADA TEKSTİL</baslik>
<adres>bakırcılar geçidi no:15 keşan</adres>
<ilce>KEŞAN</ilce>
<il>EDİRNE</il>
<telefon>+90 (284) 715 48 48</telefon>
<faks>+90 (284) 715 48 48</faks>
<latitude>40.85368</latitude>
<longtitude>26.631359</longtitude>
</MAGAZA>
....
....
</MAGAZALAR>
public class Magazalar extends FragmentActivity {
private GoogleMap googleHarita;
public String baslik[];
public String adress[];
public String ilce[];
public String il[];
public String tel[];
public String faks[];
public Double latit[];
public Double lont[];
LatLng position;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.magazalar);
try {
InputStream is = getAssets().open("file.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(is);
Element element=doc.getDocumentElement();
element.normalize();
NodeList nList = doc.getElementsByTagName("MAGAZA");
for (int i=0; i<nList.getLength(); i++) {
Node node = nList.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element2 = (Element) node;
String lati=getValue("latitude", element2);
String longt=getValue("longtitude", element2);
Double dlati= Double.parseDouble(lati);
Double dlongt=Double.parseDouble(longt);
baslik=new String[]{getValue("Baslik", element2)};
adress=new String[]{getValue("Adres", element2)};
ilce=new String[]{getValue("ilce", element2)};
il=new String[]{getValue("il", element2)};
tel=new String[]{getValue("telefon", element2)};
faks=new String[]{getValue("faks", element2)};
position=new LatLng(dlati, dlongt);
}
}
}
catch (Exception e) {e.printStackTrace();}
if (googleHarita == null) {
googleHarita = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.haritafragment))
.getMap();
if (googleHarita != null) {
LatLng istanbulKoordinat = new LatLng(41.021161,29.004065);
googleHarita.addMarker(new MarkerOptions().position(istanbulKoordinat).title("Kız Kulesi"));
googleHarita.moveCamera(CameraUpdateFactory.newLatLngZoom(istanbulKoordinat, 13));
}
googleHarita.setMapType(GoogleMap.MAP_TYPE_HYBRID);
googleHarita.setMyLocationEnabled(true);
googleHarita.getUiSettings().setMyLocationButtonEnabled(true);
}
}
private static String getValue(String tag, Element element) {
NodeList nodeList = element.getElementsByTagName(tag).item(0).getChildNodes();
Node node = (Node) nodeList.item(0);
return node.getNodeValue();
}
}