android googleMap使用并在指定的位置上标注
16lz
2021-01-24
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); }
布局文件中加入
<com.google.android.maps.MapView
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="0L96i8AoAKKTN50BsQTVZJDpNM48n34utP2nhTg"/>
android:apiKey是申请的key
不要忘记申请权限和导入mapslib
在application标签中加入
<uses-library android:name="com.google.android.maps"/>
更多相关文章
- Android(安卓)ApiDemos示例解析(183):Views->Progress Bar->2. S
- Android(安卓)Path里FillType功能
- android gpuimage显示的缩放和剪裁模式
- android中一种欢迎界面模式
- android AudioManager类 详解
- Activity四种启动模式:standard、singleTop、singleTask、singleI
- Activity启动模式设置(堆栈中的生存时间)
- android canvas实现在图片上画图
- 阅读《Android(安卓)从入门到精通》(9)——多项选择