【发布时间】:2011-07-19 19:28:18
【问题描述】:
我有一个MapView,我在上面叠加了 1,700 个点,每个点都有相同的可绘制对象,但信息不同。我目前正在使用逐项叠加来添加所有叠加,然后在钓鱼后填充。这有效,但性能很慢。改变缩放级别和焦点是跳跃的。现在,使用ArrayItemizedOverlay 会更好,因为它是相同的可绘制对象,还是地图会同样慢?
import java.util.ArrayList;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.app.Activity;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;
public class Points extends ItemizedOverlay <OverlayItem> {
Context mContext;
private ArrayList mOverlays = new ArrayList();
String newLine = String.format("%n");
public Points(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
// TODO Auto-generated constructor stub
}
@Override
protected OverlayItem createItem(int i) {
return (OverlayItem) mOverlays.get(i);
}
@Override
public int size() {
return mOverlays.size();
}
@Override
public void draw(Canvas canvas,
MapView mapView,
boolean shadow) {
if (!shadow)
super.draw(canvas, mapView, shadow);
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
}
public void populateNow(){
setLastFocusedIndex(-1);
populate();
}
public Points(Drawable defaultMarker, Context context) {
super(boundCenterBottom(defaultMarker));
mContext = context;
}
@Override
protected boolean onTap(int index) {
Intent intent = new Intent();
OverlayItem item = (OverlayItem) mOverlays.get(index);
AlertDialog.Builder dialog1 = new AlertDialog.Builder(mContext);
dialog1.setTitle(item.getTitle());
String info = item.getSnippet();
String delims = "[$]";
String [] tokens = info.split(delims);
String info1 = tokens [0];
String info2 = tokens[1];
String delims2 = "[!]";
String [] tokens2 = info1.split(delims2);
double lat = Double.parseDouble(tokens2[0]);
double lon = Double.parseDouble(tokens2[1]);
final String location = tokens2[0]+","+tokens2[1];
dialog1.setMessage(info2);
dialog1.setPositiveButton("Navigate", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Nav(location);
}
});
dialog1.setNegativeButton("Directions", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Direction(location);
}
}) ;
dialog1.show();
return true;
}
public void Nav(String location) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=" + location));
mContext.startActivity(i);
}
public void Direction(String location) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?daddr=" + location));
mContext.startActivity(i);
}
}
我如何添加项目:
mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.plug);
itemizedoverlay = new Points(drawable, this);
while (...) {
point = new GeoPoint((int) (lat * 1000000), (int) (lon * 1000000));
overlayitem = new OverlayItem(point, Station_Name, comb);
itemizedoverlay.addOverlay(overlayitem);
}
【问题讨论】:
标签: java android google-maps