(MapView和1700覆盖项目).equals(“Slow”)
我有一个MapView
,我将1,700个点叠加到它上面,每个都有相同的可绘图,但具有不同的信息。 我目前使用Itemized Overlay来添加所有覆盖层,然后一旦捕获就填充。 这有效,但性能很慢。 改变缩放级别和焦点是跳跃式的。 现在,使用ArrayItemizedOverlay
会更好吗,因为它是相同的drawable,否则地图会一样慢?
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);
}
这不是一个解决方案,而是等待完美解决方案时的解决方法。
我有同样的问题,并创建了多个覆盖。
覆盖99个点的6个覆盖点实际上快于覆盖600个点的覆盖点。
(15秒加载时间Vs 1秒)
for (int i = 0; i < 99; i++) {
webcamCursor.moveToPosition(i);
float lat = Float.valueOf(webcamCursor.getString(webcamCursor
.getColumnIndex("Lat")));
float lon = Float.valueOf(webcamCursor.getString(webcamCursor
.getColumnIndex("Lon")));
GeoPoint gp = new GeoPoint((int) (lat / 10), (int) (lon / 10));
myOverlay1.addPoint(gp);
}
for (int i = 100; i < 199; i++) {
webcamCursor.moveToPosition(i);
float lat = Float.valueOf(webcamCursor.getString(webcamCursor
.getColumnIndex("Lat")));
float lon = Float.valueOf(webcamCursor.getString(webcamCursor
.getColumnIndex("Lon")));
GeoPoint gp = new GeoPoint((int) (lat / 10), (int) (lon / 10));
myOverlay2.addPoint(gp);
}
for (int i = 200; i < 299; i++) {
webcamCursor.moveToPosition(i);
float lat = Float.valueOf(webcamCursor.getString(webcamCursor
.getColumnIndex("Lat")));
float lon = Float.valueOf(webcamCursor.getString(webcamCursor
.getColumnIndex("Lon")));
GeoPoint gp = new GeoPoint((int) (lat / 10), (int) (lon / 10));
myOverlay3.addPoint(gp);
}
for (int i = 300; i < 399; i++) {
webcamCursor.moveToPosition(i);
float lat = Float.valueOf(webcamCursor.getString(webcamCursor
.getColumnIndex("Lat")));
float lon = Float.valueOf(webcamCursor.getString(webcamCursor
.getColumnIndex("Lon")));
GeoPoint gp = new GeoPoint((int) (lat / 10), (int) (lon / 10));
myOverlay4.addPoint(gp);
}
for (int i = 400; i < 499; i++) {
webcamCursor.moveToPosition(i);
float lat = Float.valueOf(webcamCursor.getString(webcamCursor
.getColumnIndex("Lat")));
float lon = Float.valueOf(webcamCursor.getString(webcamCursor
.getColumnIndex("Lon")));
GeoPoint gp = new GeoPoint((int) (lat / 10), (int) (lon / 10));
myOverlay5.addPoint(gp);
}
for (int i = 500; i < webcamCursor.getCount(); i++) {
webcamCursor.moveToPosition(i);
float lat = Float.valueOf(webcamCursor.getString(webcamCursor
.getColumnIndex("Lat")));
float lon = Float.valueOf(webcamCursor.getString(webcamCursor
.getColumnIndex("Lon")));
GeoPoint gp = new GeoPoint((int) (lat / 10), (int) (lon / 10));
myOverlay6.addPoint(gp);
}
System.out.println("**TIME**" + (System.currentTimeMillis() - t));
mMap.getOverlays().add(myOverlay1);
mMap.getOverlays().add(myOverlay2);
mMap.getOverlays().add(myOverlay3);
mMap.getOverlays().add(myOverlay4);
mMap.getOverlays().add(myOverlay5);
mMap.getOverlays().add(myOverlay6);
在我的情况下,我会覆盖Overlay#draw()
或MapView#draw()
来检查点是否落在可见地图区域上。 使用排序的初始点数组检查更好。 但在第一次编码迭代中,我更喜欢使用上面的解决方案(Profete 162)。
还有一些可能会非常有趣的内容.. http://code.google.com/p/mapview-overlay-manager/wiki/LazyLoading
我甚至没有尝试过,只是提出了一些新的想法。
顺便说一句,我不知道我是否应该编辑我以前的答案,而不是发布一个新的答案,因为这是完全不同的。
链接地址: http://www.djcxy.com/p/53721.html上一篇: (MapView and 1700 Overlays Items).equals(" Slow")
下一篇: Disable Home Button