我無法訪問教程從Android開發者網站:http://developer.android.com/resources/tutorials/views/hello-mapview.htmlItemizedOverlay問題(HelloMapView教程)與你好地圖
我的第一個問題是,在點擊覆蓋項,應用程序會崩潰。通過確保將上下文傳遞到我創建的ItemizedOverlay類來解決此問題...
解決此問題後,覆蓋圖標不會顯示在地圖中。我可以點擊覆蓋圖所在的地圖並顯示對話框。不幸的是,我看不到圖標。我確定我引用的圖像是位於R.java資源文件中的對象。事實上,我經歷過相同的問題後,我的確切問題是由以下線程的海報提出的。不幸的是他的第二個問題從來沒有回答Context null Pointer
這裏是我的MapView類:
package com.mapsExample;
import java.util.List;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
public class HelloMaps extends MapActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable, this);
GeoPoint point = new GeoPoint(19240000,-99120000);
OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!");
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}
我的ItemizedOverlay類:
package com.mapsExample;
import java.util.ArrayList;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;
public class HelloItemizedOverlay extends ItemizedOverlay {
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
Context mContext;
public HelloItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
super(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();
}
@Override
protected boolean onTap(int index) {
OverlayItem item = mOverlays.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.show();
return true;
}
}
同樣,如果我不及格 '這個' 的ItemizedOverlay構造,圖標顯示,但不能被點擊。任何幫助深表感謝。提前致謝!
沒有跳出我作爲一個問題。試試這個示例應用程序,看看你是否有不同/更好的運氣:http://github.com/commonsguy/cw-android/tree/master/Maps/NooYawk/ – CommonsWare 2010-10-07 13:08:13