MapViewに複数のマーカーを追加しようとしていますが、動作させることができません。
LoadMarkers()を呼び出すメソッドにコメントを付けると、 。 私のコードで何が間違っているか教えてください。ItemizedOverlays Androidマップが動作しない
public class MyATMLocatorActivity extends MapActivity {
/** Called when the activity is first created. */
private MapView mapView;
private MapController myMapController;
private GeoPoint myGeoPoint;
private LocationManager myLocationManager;
private LocationListener myLocationListener;
public static Context context;
private MyItemizedOverlay myItemizedOverlay = null;
private MyLocationOverlay myLocationOverlay = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = getApplicationContext();
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
myMapController = mapView.getController();
this.LoadMarkers();
}
これは、マーカーをロードする方法..
private void LoadMArkers() {
mapView.getOverlays().clear();
mapView.postInvalidate();
OverlayItem overlayItem = null;
Drawable myATMPic = getResources().getDrawable(R.drawable.atmicon);
myATMPic.setBounds(0, 0, myATMPic.getIntrinsicWidth(), myATMPic.getIntrinsicHeight());
// Super España
myItemizedOverlay = new MyItemizedOverlay(myATMPic);
myGeoPoint = new GeoPoint((int) (-25.353043), (int) (-57.444495));
overlayItem = new OverlayItem(myGeoPoint, "Supermercado Espana","Capiatá");
myItemizedOverlay.addOverlay(overlayItem);
mapView.getOverlays().add(myItemizedOverlay);
// Martín Ledesma
myItemizedOverlay = new MyItemizedOverlay(myATMPic);
myGeoPoint = new GeoPoint((int) (-25.353974), (int) (-57.445214));
overlayItem = new OverlayItem(myGeoPoint, "Martín Ledesma", "Capiatá");
myItemizedOverlay.addOverlay(overlayItem);
mapView.getOverlays().add(myItemizedOverlay);
mapView.postInvalidate();
}
であり、これは私のItemizedOverlay()クラス
public class MyItemizedOverlay extends com.google.android.maps.ItemizedOverlay<OverlayItem> {
private Context mContext;
private ArrayList<OverlayItem> myOverlaysArray = new ArrayList<OverlayItem>();;
private GeoPoint geoPoint = null;
public MyItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
public MyItemizedOverlay(Drawable defaultMarker, Context context) {
super(boundCenterBottom(defaultMarker));
mContext = context;
}
public void addOverlay(OverlayItem overlay) {
myOverlaysArray.add(overlay);
populate();
}
@Override
protected OverlayItem createItem(int i) {
return myOverlaysArray.get(i);
}
// Removes overlay item i
public void removeItem(int i) {
myOverlaysArray.remove(i);
populate();
}
// Returns present number of items in list
@Override
public int size() {
return myOverlaysArray.size();
}
public void addOverlayItem(OverlayItem overlayItem) {
myOverlaysArray.add(overlayItem);
populate();
}
public void addOverlayItem(int lat, int lon, String title) {
try {
geoPoint = new GeoPoint(lat, lon);
OverlayItem overlayItem = new OverlayItem(geoPoint, title, null);
addOverlayItem(overlayItem);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected boolean onTap(int index) {
OverlayItem item = myOverlaysArray.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.show();
return true;
}
}
が私の解決策を確認しています。 – JustinDanielson
はあなたの問題を解決しましたか? –