android地图中的一个例子
来源:互联网 发布:淘宝网客户端电脑版 编辑:程序博客网 时间:2024/04/27 22:47
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;
}
}
/** 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;
}
}
- android地图中的一个例子
- Android百度地图例子
- Android百度地图实践 Demo中的一个Application类
- android中的AsyncTask例子
- C++ Templates 中的一个例子
- isapi中的一个转向例子
- js中的一个闭包小例子
- tomcat中的一个过滤器例子
- 百度地图插件,最简单的一个例子
- Android ViewFlow的一个例子
- 一个Android Socket的例子
- 一个Android Socket的例子
- Android SharedPreferences 一个小例子
- Android ExpandableListView 一个小例子
- 一个Android Socket的例子
- Android popupWindow一个小例子
- 一个Android Service小例子
- 一个Android Socket的例子
- php中的方法链
- (转)curl post的问题
- MKV文件解析实例
- 介绍一个分享社会化web信息的分享工具
- vs.net 2010两个数据库方面的好工具
- android地图中的一个例子
- Android中对json的解析和处理
- android中判断横屏或者竖屏并改变背景
- (转)一个android下的重力模拟器
- android中模拟器中实现GPS坐标改变
- Android中使用httpclient等小结
- 使用android内置相机拍照
- 一个图片预加载效果
- firebug调试小tips:cd