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;
}
@Override
public 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"/>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值