程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> map- Android MapView顯示Google地圖

map- Android MapView顯示Google地圖

編輯:編程綜合問答
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();
    }

最佳回答:


http://blog.csdn.net/zlqqhs/article/details/8548439
http://blog.csdn.net/zlqqhs/article/details/8559207

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved