`
hualikejava
  • 浏览: 169756 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

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"/>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics