我跟着谷歌的地圖視圖教程從這個鏈接http://developer.android.com/resources/tutorials/views/hello-mapview.html
我做了第一個關於創建地圖活動,但有添加覆蓋問題。這裏是源代碼:谷歌地圖視圖教程 - 覆蓋
package rs.iz.stevy.wifi;
import java.util.ArrayList;
import android.graphics.drawable.Drawable;
import android.app.AlertDialog;
import android.content.Context;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;
public class Overlay extends ItemizedOverlay {
public Overlay(Drawable defaultMarker, Context context) {
super(defaultMarker);
Context mContext;
mContext = context;
}
private ArrayList<OverlayItem>mOverlays= new ArrayList<OverlayItem>();
public Overlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
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;
}
}
錯誤出現在該行: AlertDialog.Builder對話框=新AlertDialog.Builder(mContext); Eclipse顯示mContext無法解析爲變量。
這裏是Activity類:
rs.iz.stevy.wifi;
import java.util.List;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
public class WiFiKupacicaActivity extends MapActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mapa= (MapView) findViewById(R.id.Mapa1);
mapa.setBuiltInZoomControls(true);
mapa.setSatellite(true);
GeoPoint initGeoPoint = mapa.getMapCenter();
List<Overlay> mapOverlays = mapa.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.kupacica);
Overlay itemizedoverlay = new Overlay (drawable);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
的Eclipse顯示錯誤在該線無法實例疊加: 疊加itemizedoverlay =新重疊(繪製);
如果您在這裏看到任何可以輕鬆修復的錯誤,請回答因爲這是我第一次嘗試編寫Android應用程序。
@問題在於您用於添加疊加層的類名因此首先需要將類疊加層的名稱更改爲任何其他您喜歡MapOverlay然後將其擴展到ItemizedOverlay。 – Herry