私はMapView
を持っています。それに1,700ポイントを重ねて表示しています。私は現在Itemized Overlayを使って、すべてのオーバーレイを追加してから、一度フィッシュします。これは機能しますが、パフォーマンスは低速です。ズームレベルとピントを変えるのは難しいです。さて、同じドロアブルなのでArrayItemizedOverlay
を使用する方が良いでしょうか、それとも地図が遅くなるでしょうか?(MapViewと1700オーバーレイアイテム).equals( "Slow")
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);
}
私はこれを試してみましたが、それは速くはありませんでした。追加するアイテムは108個あり、3つのパーティションに分割しました。私が使った方法にかかわらず、ほぼ同じ速度でした。 – dermatthias
はい、私は私の例で100のアイテムを使用しています。スピードが落ち始めると限界が150アイテムになると思いますので、心配する必要はありません。 –