我已经从我的 php 中解析了 xml 代码(通过 XML DOM 方法),其中包含 POI 列表的纬度、经度。我想使用来自单独类的引脚显示所有点。问题是当我打开应用程序时我不想要列表视图,它应该打开地图并显示所有标记。有人可以帮我吗?提前致谢。
代码
import java.util.ArrayList;
import java.util.HashMap;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class ParseXMLaroundme extends ListActivity{
String latitude;
public ParseXMLaroundme () {
// TODO Auto-generated constructor stub
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.aroundme);
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
String xml = ParseXMLMethods.getXML();
Document doc = ParseXMLMethods.XMLfromString(xml);
/*
int numResults = ParseXMLMethods.numResults(doc);
if((numResults <= 0)){
Toast.makeText(ParseXMLDemo.this, "There is no data in the xml file", Toast.LENGTH_LONG).show();
finish();
}
*/
NodeList children = doc.getElementsByTagName("ListingElement");
for (int i = 0; i < children.getLength(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element)children.item(i);
map.put("ItemID", ParseXMLMethods.getValue(e, "ItemID"));
map.put("ImageURL", ParseXMLMethods.getValue(e, "ImageURL"));
map.put("VideoURL", ParseXMLMethods.getValue(e, "VideoURL"));
map.put("AudioURL", ParseXMLMethods.getValue(e, "AudioURL"));
map.put("StartDate", ParseXMLMethods.getValue(e, "StartDate"));
map.put("EndDate", ParseXMLMethods.getValue(e, "EndDate"));
map.put("ItemName", ParseXMLMethods.getValue(e, "ItemName"));
map.put("Address", ParseXMLMethods.getValue(e, "Address"));
map.put("Suburb", ParseXMLMethods.getValue(e, "Suburb"));
map.put("Postcode", ParseXMLMethods.getValue(e, "Postcode"));
map.put("Longitude", ParseXMLMethods.getValue(e, "Longitude"));
map.put("Latitude", ParseXMLMethods.getValue(e, "Latitude"));
map.put("SubtypeName", ParseXMLMethods.getValue(e, "Subtypename"));
map.put("Cost", ParseXMLMethods.getValue(e, "Cost"));
map.put("Details", ParseXMLMethods.getValue(e, "Details"));
map.put("Website", ParseXMLMethods.getValue(e, "Website"));
map.put("MajorRegionName", ParseXMLMethods.getValue(e, "MajorRegionName"));
map.put("Phone", ParseXMLMethods.getValue(e, "Phone"));
map.put("Email", ParseXMLMethods.getValue(e, "Email"));
map.put("OpeningHours", ParseXMLMethods.getValue(e, "OpeningHours"));
String targetlatitude=map.get("latitude");
String targetlongitude=map.get("longitude");
Double targetlat = Double.valueOf(targetlatitude);
Double targetlng = Double.valueOf(targetlongitude);
mylist.add(map);
}
/*
ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.me_layout,
new String[] { "Latitude", "Longitude", "VideoURL", "StartDate", "EndDate", "ItemName" },
new int[] { });
setListAdapter(adapter);
*/
final ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
@SuppressWarnings("unchecked")
HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);
Toast.makeText(ParseXMLaroundme.this,o.get("NewsBody"), Toast.LENGTH_LONG).show();
}
});
}
}