aa2218018164 2013-02-21 06:31 采纳率: 100%
浏览 4291
已采纳

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

查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 调用函数时,无关变量的改变引起函数值的改变
  • ¥15 xy坐标转化为经纬度坐标
  • ¥15 一般三角模糊数的上界值和下届值取中值的多少比较合理?
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥20 Hbase启动失败,无法启动HMaster
  • ¥15 sqpingboot在父模块已经引入了mybatisplus 在子组件不写版本号还是报错
  • ¥20 Lumerical FDTD solutions 中模型的相对阻抗,有效介电常数和有效磁导率的实部和虚部的数据如何获得?
  • ¥100 sql reporting service 远程smtp服务器配置支持
  • ¥15 ppyoloe_r带角度目标检测,loss_cls没法收敛
  • ¥15 淘宝交易指数如何解读,其关联的数据指标是什么