android googleMap使用并在指定的位置上标注
1.使用googleMap 项目必须使用google APIS
2.必须申请key
protected void onCreate(Bundle arg0) {super.onCreate(arg0); setContentView(R.layout.map);mapView = (MapView)findViewById(R.id.map);// 设置显示模式 // mapView.setTraffic(true); mapView.setSatellite(true);//是否卫星模式 mapView.setStreetView(false); //设置缩放模式 mapView.setBuiltInZoomControls(true); GeoPoint geoPoint = new GeoPoint((int)(22.548723*1E6),(int)(113.936591*1E6)); mapCon=mapView.getController(); mapCon.setCenter(geoPoint); mapCon.setZoom(15); Projection projection = mapView.getProjection(); //进行画布 List<Overlay> overlays = mapView.getOverlays(); overlays.add(new MyPostionOverlay(projection,geoPoint )); }
/** * 主要是画图 将标记位置 * @author Administrator * */public class MyPostionOverlay extends Overlay {private Projection projection;private GeoPoint geoPoint; public MyPostionOverlay(Projection projection, GeoPoint geoPoint ){this.projection=projection;this.geoPoint=geoPoint;}@Overridepublic void draw(Canvas canvas, MapView mapView, boolean shadow) {super.draw(canvas, mapView, shadow);//准备园图Point point = new Point();Paint paint = new Paint();paint.setColor(Color.RED);paint.setAntiAlias(true);paint.setStyle(Style.FILL);//经度转像素projection.toPixels(geoPoint, point);//将图画到上层canvas.drawCircle(point.x, point.y, 6.0f, paint); }