1
嗨iam在android.while中顯示谷歌地圖中的多個標記iam顯示時,標記在谷歌地圖上一一顯示。在這裏我想顯示多於50個標記。但根據我的代碼,標記逐個顯示,並顯示50個標記,這需要花費很多時間。下面是我的代碼,它處於同一個類中。任何想法都會被讚賞。如何在Google地圖中一次顯示多個標記android
公共無效displayMarkersOnMap(){
Runnable r=new Runnable(){
public void run(){
對(INT I = 0;我< vector.size();我++){
try {
pinHM = (HashMap<String, Object>)vector.get(i);
mapView = (MapView)findViewById(R.id.mapView);
mapView.getController().setZoom(9);
Drawable marker;
else{
String status = pinHM.get("status").toString();
if (status.equals("ST_COMPLETE")) {
marker = getResources().getDrawable(R.drawable.pin_green);
}else if (status.equals("ST_IN_PROGRESS")) {
marker = getResources().getDrawable(R.drawable.pin_orange);
}else {
marker = getResources().getDrawable(R.drawable.pin_gray);
}
}
marker.setBounds((int) (-marker.getIntrinsicWidth()/2),-marker.getIntrinsicHeight(),(int) (marker.getIntrinsicWidth()/2), 0);
double latitude=Double.parseDouble(pinHM.get("latitude").toString());
double longitude=Double.parseDouble(pinHM.get("longitude").toString());
Geocoder geoCoder = new Geocoder(BaseMapActivity.this, Locale.getDefault());
List<Address> addresses = geoCoder.getFromLocationName(address,5);
if (addresses.size() > 0) {
GeoPoint point = new GeoPoint((int)(latitude*1E6),(int)(longitude*1E6));
funPlaces = new MyItemizedOverlay(point,marker,hmtostring,nameaddress,mapView);
mapView.getOverlays().add(funPlaces);
GeoPoint pt = funPlaces.getCenterPt();
int latSpan = funPlaces.getLatSpanE6();
int lonSpan = funPlaces.getLonSpanE6();
Log.v("Overlays", "Lat span is " + latSpan);
Log.v("Overlays", "Lon span is " + lonSpan);
MapController mc = mapView.getController();
mc.setCenter(pt);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}//end of run
};//end of Runnable
Thread thread = new Thread(r, "BaseMapActiviy");
thread.start();
}
公共類MyItemizedOverlay延伸BalloonItemizedOverlay {
private ArrayList<OverlayItem> m_overlays = new ArrayList<OverlayItem>();
@SuppressWarnings("unused")
private Context c;
private GeoPoint center = null;
public MyItemizedOverlay(GeoPoint point, Drawable marker,String hmtostring,String nameaddress,MapView mapView) {
super(boundCenter(marker), mapView);
c = mapView.getContext();
m_overlays.add(new OverlayItem(point,hmtostring,nameaddress));
populate();
}
public GeoPoint getCenterPt() {
if (center == null) {
int northEdge = -90000000;
int southEdge = 90000000;
int eastEdge = -180000000;
int westEdge = 180000000;
Iterator<OverlayItem> iter = m_overlays.iterator();
while (iter.hasNext()) {
GeoPoint pt = iter.next().getPoint();
if (pt.getLatitudeE6() > northEdge)
northEdge = pt.getLatitudeE6();
if (pt.getLatitudeE6() < southEdge)
southEdge = pt.getLatitudeE6();
if (pt.getLongitudeE6() > eastEdge)
eastEdge = pt.getLongitudeE6();
if (pt.getLongitudeE6() < westEdge)
westEdge = pt.getLongitudeE6();
}
center = new GeoPoint((int) ((northEdge + southEdge)/2),
(int) ((westEdge + eastEdge)/2));
}
return center;
}
@Override
public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
if (!shadow) {
super.draw(canvas, mapView, shadow);
}
return false;
}
public void addOverlay(OverlayItem overlay) {
m_overlays.add(overlay);
populate();
}
@Override
protected OverlayItem createItem(int i) {
return m_overlays.get(i);
}
@Override
public int size() {
return m_overlays.size();
}
@Override
protected boolean onBalloonTap(int index) {
return true;
}
}