目前在做一個顯示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