问题描述
我的qestion可能很容易sinse我的Android初学者。
My qestion might be easy sinse I'm android begginer.
我继的
和在创建地图活动的第一部分有成功。
但现在我想补充一个覆盖项目。现在的问题是在我的.java code:
and have succeed in a first part of creating a map activity.But now I'm trying to add an overlay items. The problem is in my .java code:
List<Overlay> mapOverlays = mapView.getOverlays();
此行是所有教程psented $ P $。但我得到类似的错误信息:该方法getOverlays)(未定义该类型的MapView。
任何人可以帮助我解决这个问题?
this line is presented in all tutorials. But I get the error message like: 'The method getOverlays() is undefined for the type MapView'.Can anybody help me to solve it?
code:
package com.example.mapsdemo;
import java.util.List;
import com.google.android.gms.maps.MapView;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
public class MainActivity extends Activity {
private MapView mapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.marker);
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);
}
}
第二类是在这里:
public class HelloItemizedOverlay extends ItemizedOverlay {
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
public Context mContext ;
public HelloItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
public HelloItemizedOverlay(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();
}
@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;
}
}
感谢您的帮助!
推荐答案
您在混合德precated API与V1 V2 API
You are mixing deprecated API v1 with API v2.
我建议删除所有code和下面这个:
I'd suggest removing all the code and following this instead: https://developers.google.com/maps/documentation/android/start
这篇关于为什么getOverlays()是未定义的MapView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!