gpt4 book ai didi

android - 将 xml 数据解析为 google map android

转载 作者:行者123 更新时间:2023-11-30 03:59:02 26 4
gpt4 key购买 nike

我正在制作一个程序,我必须在其中将 xml 数据解析为谷歌地图,我知道如何使用 xml 解析器和谷歌地图的一些知识,在这里我需要从 xml 文件中获取经度、纬度、名称和地址,以及需要使用标记在谷歌地图中显示,请有人帮我做这个,我将我的 xml 数据放在下面:-

    <map>
<area>
<longitude>-97.762914</longitude>
<latitude>30.282165</latitude>
<name>Place Name 1</name>
<address>Place Address 1</address>
</area>
<area>
<longitude>-97.762914</longitude>
<latitude>31.282165</latitude>
<name>Place Name 3</name>
<address>Place Address 3</address>
</area>
<area>
<longitude>-97.762914</longitude>
<latitude>32.282165</latitude>
<name>Place Name 3</name>
<address>Place Address 3</address>
</area>
</map>

最佳答案

MapView mapView = new MapView(this, mapkey);
MapController mc=mapView.getController();
GeoPoint myLocation = null;
Drawable drawable = this.getResources().getDrawable(R.drawable.map_marker);
myItemizedOverlay itemizedoverlay = new myItemizedOverlay(drawable, this);
GeoPoint ppoint = new GeoPoint(platt,plngg); //platt and plngg xml parser value lattitude and Longitude
OverlayItem poverlayitem = new OverlayItem(ppoint,bankname,name of the place);
itemizedoverlay.addOverlay(poverlayitem);
mapOverlays.add(itemizedoverlay);
myLocation = new GeoPoint(platt,plngg);
mc.animateTo(myLocation);
mapView.setBuiltInZoomControls(true);
mapView.setClickable(true);
mc.setZoom(14);
mapView.invalidate();
return mapView;

MyItemizedOverlay 类 --> 用于在 map 中绘制图钉

public class myItemizedOverlay extends ItemizedOverlay<OverlayItem> {

private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private Context mContext;


public myItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}

public myItemizedOverlay(Drawable defaultMarker, Context context) {
super(boundCenterBottom(defaultMarker));
mContext = context;
}

public void addOverlay(OverlayItem overlay){
mOverlays.add(overlay);
populate();
}

@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}

public void removeItem(int i){
mOverlays.remove(i);
populate();
}

@Override
public int size() {
return mOverlays.size();
}

@Override
protected boolean onTap(int i) {
OverlayItem item = mOverlays.get(i);
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.show();
return true;
}



}

关于android - 将 xml 数据解析为 google map android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12853370/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com