android地图中的一个例子

public class AndroidGooleMapDemo extends MapActivity {
/** Called when the activity is first created. */
private MapView mMapView;
private MapController mMapController;
private GeoPoint mGeoPoint;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mMapView = (MapView) findViewById(R.id.MapView01); // 设置为交通模式
mMapView.setTraffic(true);

// //设置为卫星模式

// mMapView.setSatellite(true);

// //设置为街景模式

// //mMapView.setStreetView(false);

// //取得MapController对象(控制MapView)

mMapController = mMapView.getController();

mMapView.setEnabled(true);

mMapView.setClickable(true);
// //设置地图支持缩放
mMapView.setBuiltInZoomControls(true);
// //设置起点为成都
mGeoPoint=new GeoPoint((int)(30.659259*1000000),(int)(104.065762*1000000));

// //定位到成都
mMapController.animateTo(mGeoPoint);

// //设置倍数(1-21)

mMapController.setZoom(12);


// //添加Overlay,用于显示标注信息

MyLocationOverlay myLocationOverlay = new MyLocationOverlay();

List<Overlay> list= mMapView.getOverlays();

  list.add(myLocationOverlay);
}
protected boolean isRouteDisplayed()
{
return false;
}
class MyLocationOverlay extends Overlay
{
public boolean draw(Canvas canvas,MapView mapView,boolean shadow,long when) 
{      
super.draw(canvas, mapView, shadow);     
Paint paint = new Paint();
Point myScreenCoords = new Point();       
     

// 将经纬度转换成实际屏幕坐标      
   mapView.getProjection().toPixels(mGeoPoint,myScreenCoords);   
   paint.setStrokeWidth(1);   
      paint.setARGB(255, 255, 0, 0);   
      paint.setStyle(Paint.Style.STROKE); 
        Bitmap bmp = BitmapFactory.decodeResource(getResources(),R.drawable.home);    
     canvas.drawBitmap(bmp,myScreenCoords.x,myScreenCoords.y,paint);   
     canvas.drawText("天府广场",myScreenCoords.x, myScreenCoords.y,paint);     
     return true; 

}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值