Здравствуйте! Я использую это руководство для создания mapView и mapOverlays: http://developer.android.com/resources/tutorials/views/hello-mapview.html
и вот мой код:
мой mapoverlay (mapItem):
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private Context mContext;
public MapItem(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
public MapItem(Drawable defaultMarker, Context context) {
super(boundCenterBottom(defaultMarker));
mContext = context;
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}
@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
@Override
public int size() {
return mOverlays.size();
}
//remove oldest element
public void remove(){
mOverlays.remove(0);
}
@Override
protected boolean onTap(int index) {
OverlayItem item = mOverlays.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext); //row 50
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.show();
return true;
}
}
мой класс просмотра карты (mapViewActivity):
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapview);
setupListener();
final MapView mapView = (MapView) findViewById(R.id.mapview);
mapController = mapView.getController();
mapView.setBuiltInZoomControls(true);
mapView.setClickable(true);
//Store resources
final List<Overlay> storeOverlays = mapView.getOverlays();
Drawable storePic = this.getResources().getDrawable(R.drawable.storemarker);
final MapItem itemizedStoreOverlay = new MapItem(storePic);
mapController.setZoom(13); // defualt zoom
//Plot all stores on the map
df = ((ClassHandler)getApplication()).getDatabaseFacade();
Cursor plotstore = df.getAllStorePos("Göteborg");
startManagingCursor(plotstore);
plotstore.moveToFirst();
while(plotstore.isAfterLast() == false){
GeoPoint addStore = new GeoPoint(plotstore.getInt(plotstore.getColumnIndex("lat")), plotstore.getInt(plotstore.getColumnIndex("long")));
OverlayItem overlayitem = new OverlayItem(addStore, plotstore.getString(plotstore.getColumnIndex("_id")), plotstore.getString(plotstore.getColumnIndex("address")));
itemizedStoreOverlay.addOverlay(overlayitem);
storeOverlays.add(itemizedStoreOverlay);
plotstore.moveToNext();
}
//Get current position
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
GeoPoint currentPos = new GeoPoint((int)(location.getLatitude()*1000000), (int)(location.getLongitude()*1000000));
mapController.animateTo(currentPos);
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status,
Bundle extras) {
// TODO Auto-generated method stub
}
};
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
//add current position
MyLocationOverlay myLocationOverlay = new MyLocationOverlay(this, mapView);
mapView.getOverlays().add(myLocationOverlay);
myLocationOverlay.enableMyLocation();
//myLocationOverlay.disableMyLocation();
}
private void setupListener() {
MapListener listener = new MapListener();
}
}
Проблема в том, что когда я нажимаю на маркер магазина, моя программа падает с этой ошибкой:
http://elysobi.kjm.sgsnet.se:81/public/Android/ERROR.png
где строка 50 в mapItem отмечена на моем mapoverlay.
Кто-нибудь знает, в чем проблема?
/ Спасибо за помощь, Бен.