2 aa2218018164 aa2218018164 于 2013.02.21 14:31 提问

Android MapView显示Google地图

目前在做一个显示Google地图的案例,以前从来没整过所以这次试试

看了网上做法做的,也导入了Jar包。apiSDK也有,权限也给了,但是运行的时候还是启动不起来

下面是我的代码

   private MapView map;
    private MapController mc;

//  private LocationManager locationManager;
//  private LocationListener locationListener;
    private static final int latitudeE6=37985339;
    private static final int longitudeE6=23716735;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        map = (MapView) findViewById(R.id.map);
        mc=map.getController();
        map.setBuiltInZoomControls(true);

        List<Overlay> mapOverlay=map.getOverlays();
        Drawable drawable=this.getResources().getDrawable   (R.drawable.ic_action_search);
        CustomItemizedOverlay itemizedOverlay=new CustomItemizedOverlay(drawable,this);
        GeoPoint point=new GeoPoint(latitudeE6, longitudeE6);
        OverlayItem overlayItem=new OverlayItem(point, "Hello","I'm in Athens,Greece");

        itemizedOverlay.addOverlay(overlayItem);
        mapOverlay.add(itemizedOverlay);
        mc.animateTo(point);
        mc.setZoom(6);

    }


     public class CustomItemizedOverlay extends ItemizedOverlay<OverlayItem> {

    private ArrayList<OverlayItem> mapOverlays=new ArrayList<OverlayItem>();
    private Context context;



    public CustomItemizedOverlay(Drawable defaultMarker) {
        super(defaultMarker);
        // TODO Auto-generated constructor stub
    }

    public CustomItemizedOverlay(Drawable defaultMarker,Context context) {
        this(defaultMarker);
        this.context=context;
        // TODO Auto-generated constructor stub
    }



    @Override
    protected OverlayItem createItem(int item) {
        // TODO Auto-generated method stub
        return mapOverlays.get(item);
    }

    @Override
    public int size() {
        // TODO Auto-generated method stub
        return mapOverlays.size();
    }

    @Override
    protected boolean onTap(int index) {
        // TODO Auto-generated method stub
        OverlayItem item=mapOverlays.get(index);
        AlertDialog.Builder dialog=new AlertDialog.Builder(context);
        dialog.setTitle(item.getTitle());
        dialog.setMessage(item.getSnippet());
        dialog.show();
        return true;
    }

    public void addOverlay(OverlayItem overlay){
        mapOverlays.add(overlay);
        this.populate();
    }

3个回答

zlQQhs
zlQQhs   2013.02.25 23:29
已采纳
sasuke38
sasuke38   2013.02.21 14:32
aa2218018164
aa2218018164 额。英文的,好难看懂
4 年多之前 回复
easonx1990
easonx1990   2013.02.26 11:47

如果用AVD跑的话,需要用Google API那个包

Csdn user default icon
上传中...
上传图片
插入图片