我希望获得关于获取纬度和经度的一些帮助。我的意思是:我从网上解析了经纬度(使用XMLPullParser)。现在,我最大的问题是获取所有的值(经纬度)并将它们绘制在地图上。请帮忙!在地图上动态显示Android多重覆盖
这里是我的分析器类:
public class Parser {
//Feed Parsing Method
public ArrayList<Bakery> parse(String url) {
//Array of Episode Objects
ArrayList<Bakery> bakeries = null;
try {
//Encode the URL into a URL Object
URL bakery_feed_url = new URL(url);
//Open a Connection to the feed
XmlPullParser parser = Xml.newPullParser();
try {
parser.setInput(bakery_feed_url.openConnection().getInputStream(), null);
} finally {
}
int event_type = parser.getEventType();
Bakery current_bakery = null;
boolean done = false;
//Parse the feed, start reading throughout the feed from top to bottom
while (event_type != XmlResourceParser.END_DOCUMENT && !done){
String tag_name = null;
/*
lat = Integer.parseInt(parser.getAttributeValue(null,"lat"));
lon = Integer.parseInt(parser.getAttributeValue(null,"lon"));
grade = Integer.parseInt(parser.getAttributeValue(null,"grade"));
*/
switch (event_type){
//Found the start of the feed
case XmlResourceParser.START_DOCUMENT:
bakeries = new ArrayList<Bakery>();
break;
//Found a start tag
case XmlResourceParser.START_TAG:
//apply the data to our Episode object based on the tag name
tag_name = parser.getName();
if(tag_name.equalsIgnoreCase("place")){
current_bakery = new Bakery();
}else if(current_bakery != null){
if (tag_name.equalsIgnoreCase("phone_number")){
current_bakery.setPhone(parser.nextText());
}else if(tag_name.equalsIgnoreCase("city")){
current_bakery.setCity(parser.nextText());
}else if(tag_name.equalsIgnoreCase("province")){
current_bakery.setState(parser.nextText());
}else if(tag_name.equalsIgnoreCase("address")){
current_bakery.setAddress(parser.nextText());
}else if(tag_name.equalsIgnoreCase("lat")){
current_bakery.setLatitude(parser.nextText());
//double lat = Integer.parseInt(parser.getAttributeValue(null,"lat"));
// current_bakery.setLater(Integer.parseInt(parser.getAttributeValue(null, "lat")));
}else if(tag_name.equalsIgnoreCase("postal_code")){
current_bakery.setZip(parser.nextText());
}else if(tag_name.equalsIgnoreCase("lng")){
current_bakery.setLongitude(parser.nextText());
}else if(tag_name.equalsIgnoreCase("name")){
current_bakery.setPlace_name(parser.nextText());
}
}
break;
//An end tag has been reached
case XmlResourceParser.END_TAG:
tag_name = parser.getName();
//End of an Episode Item
if (tag_name.equalsIgnoreCase("place") && current_bakery != null){
bakeries.add(current_bakery);
//Reached the end of all bakeries, no more data to collect
} else if (tag_name.equalsIgnoreCase("places")){
done = true;
}
break;
}
event_type = parser.next();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
//Return the Episode Array
return bakeries;
}
}
正如你看到的,我解析的纬度和经度好的,但同样的,因为我得到这一切为字符串,我有麻烦将其转换为INT然后将其提供给OverlayItems类。我希望我不会让这个过于复杂。
你好!我知道这已经有一段时间了,但对于@CornFlakesDK我仍然有一个快速的问题。什么是myList.size?也是Foo应该是获得经纬度的类?对不起,这些该死的问题,但我需要知道。 – ito 2011-06-03 07:29:07
如果您有后续问题,请更好地发布新问题,而不是在答案中编辑新问题。更多的人会以这种方式看到你的问题,并试图回答。 – sth 2011-06-05 03:05:32