aa2218018164
2013-02-21 06:31
采纳率: 100%
浏览 4.3k

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条回答 默认 最新

  • zlQ_ 2013-02-25 15:29
    已采纳
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • Jobernowl 2013-02-21 06:32
    评论
    解决 无用
    打赏 举报
  • EasonX 2013-02-26 03:47

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

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题