【发布时间】:2011-10-03 01:17:41
【问题描述】:
我刚开始 Android 开发,正在开发一个与 google maps api 相关的小应用程序。我为此使用谷歌地图视图并关注this tutorial..
我创建了一个自定义 itemizedOverlay,它有一个这样的构造函数(如教程中所述) -
public pujaItemizedOverlay(Drawable defaultMarker, Context context) {
super(defaultMarker);
mContext = context;
}
我在res/drawable/ 文件夹中有一个名为sprite.png 的图像文件。这是我的 onCreate() 函数 -
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.sprite);
pujaItemizedOverlay itemizedoverlay = new pujaItemizedOverlay(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);
}
问题是,名为 sprite 的图像没有显示在地图上。
我想提到的一个是,根据教程,他们向 Context 类的自定义 itemizedOverlay 的构造函数添加了第二个参数。但是在他们的示例中,当他们调用该叠加层时,他们只提供了一个参数(查看教程页面),例如 -HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable);
Eclipse 在这一行中显示了一个明显的错误,因此我将第二个参数添加为this 以提供当前上下文。我在这里做吗?
更新:
有问题的图片是here。
【问题讨论】:
-
Why are my overlays on a mapview not shown? 的可能副本。如果有任何模组,请关闭此问题。