八月四号

Satellite
卫星

longitude
经度

latitude
纬度

interval
间隔

distance
距离

render
给予

graphic
图像

The Android framework APIs provides a set 2D drawing APIs that
allow you to render your own custom graphics onto a canvas or to
modify existing Views to customize their look and feel

personall
亲自地

appropriate
适合的

This way, you personally call the appropriate
class's onDraw() method (passing it your Canvas)

performance-intensive
性能要求较高的

wherein
其中

surface
表面

typically
通常

hierarchy
等级
In this manner, the drawing of your graphics is handled by
the system's normal View hierarchy drawing process

variety
种类

behave in unique ways
独特的显示方式

you can also extend these to define your own
custom Drawable objects that behave in unique ways.

coordinate
坐标,协调


 习惯上说的经纬度.但GeoPoint的构造方法却是纬度,经度.

GeoPoint gp = new GeoPoint(int latitude,int longitude);

今天学习了一下书里的googlemap部分.马马虎虎大概了解了下googlemap.

够面试的水平吧.

下午锅皮给我打电话还安慰我来着,让我慢慢找工作,听他说 好像现在大家都过得不好啊.

昨天晚上手一贱,,更新了ADT.从17到20了.好不习惯啊.但是弄不回去了.真尴尬.

请求地址有空格时用加号替换空格

 

MapView支持的常用方法:

MapController  getController():获取该MapView所关联的MapController.

GeoPoint  getMapCenter():获取该MapView所显示的中心.

int  getMaxZoomLevel(): 获取该MapView所支持的最大的放大级别.

List<Overlay> getOverLays(): 获取该MapView上显示的全部Overlay.

Projection  getProjection(): 获取屏幕像素坐标与经纬度坐标之间的投影关系.

int  getZoomLevel(): 获取该屏幕当前的缩放级别.

setSatellite(boolean on):设置是否显示卫星地图

setTraffic(boolean on): 设置是否显示交通情况.

 

MapView的getController()方法会返回该MapView所关联的MapController对象,MapController可以对该MapView进行控制,比如控制地图定位到指定位置或地图的放大缩小等.

 

MapView的方法中还包括一个getOverls()方法,该方法将会返回该MapView上所有Overlay对象.Overlay是附加在Google Map上的附加图片,应用它可以控制向Google Map上添加任意多个Overlay对象.

 

为了表示Google Map上的指定点,Google Map为Android提供了一个GeoPoint类.

GeoPoint类十分简单,它就是对经纬度的封装.需要指出的是,当程序创建GeoPoint

对象的时候,需要先把longgitude和latitude的值先乘以10的6次方.

// 将经纬度信息包装成GeoPoint对象

GeoPoint gp = new GeoPoint((int) (latitude * 1E6), (int) (longitude * 1E6));

除此之外,MapController还提供了一个animateTo(GeoPoint point)方法,

该方法控制地图定位到指定的地理位置.

 

应用中调用Google Map服务主要依赖于MapView,MapController,GeoPoint这三个API.

在清单文件中的application节点下声明

<!-- 声明需要使用Google Map API -->

<uses-library android:name="com.google.android.maps" />

在布局文件中使用mapview就像使用普通的imageview一样,

只是需要多加一个apikey标签

<com.google.android.maps.MapView

       android:id="@+id/mv"

       android:clickable="true"

       android:enabled="true"

       android:layout_width="fill_parent"

       android:layout_height="fill_parent"

       android:apiKey="xxxxxxx" />

</LinearLayout>

 

在使用mapview的Activitity一定要继承MapActivity

注意这个MainActivity要继承MapActivity

在MainActivity中获取mapview跟获取普通控件一样

mapview = findViewById(R.id.mapview);

 

//创建在mapview中要显示的放大缩小按钮

mapview.setBuildInZoomControls(true);

//创建mapController对象

MapController mc = mapview.getController();

 

//设置mapview显示的视图

//设置satellite为false则为正常视图

mapview.setSatellite(false);

//设置mapview的satellite为true则为卫星视图

mapview.setSatellite(true);

 

/**根据经纬度将MapView定位到指定地点的方法示例*/

private void updateMapView(double Dlongitude,double Dlatitude)

{

//先转换成int 记得乘以10的6次方 1E6

int longitude = (int)Dlongitude * 1E6;

int latitude = (int)Dlatitude * 1E6;

//将经纬度信息包装成GeoPoint对象


 

GeoPoint gp = new GeoPoint(latitude,longitude);(注意这里是纬经度)


 

//显示MapView中的放大缩小按钮

mapview.displayZoomControls(true);

 

//创建MapController对象

MapController control = mapview.getController();

 

//将地图移动到指定的地理位置

control.animateTo(gp);

 

//获取MapView上所有的Overlay对象

List<Overlay> overlays = mapview.getOverlays();

 

//清除原有的Overlay对象

overlays.clear();

 

//为下面的overlay作准备

//这就是一个显示位置的小图标而已

Bitmap bitmap= BitmapFactory.decodeResource

(getResource(),R.drawable.pos);

 

//这个PosOverLay为一个自定义类

PosOverlay  posOverlay = new PosOverlay(geopoint,bitmap);

 

//添加一个新的overlay对象

overlays.add(posOverlay);

}

以下是自定义PosOverlay类

private class PosOverlay extends Overlay

{

   //定义该Posoverlay要绘制的位图

   private Bitmap bitmap;

   //定义该Posoverlay绘制位图的位置

   private GeoPoint geopint;

 

   public PosOverlay(GeoPoint gp,Bitmap bitmap)

   {

       this.geopoint = geopoint;

       this.bitmap = bitmap;

   }

 

   @Override

   public void draw(Canvas canvas,MapView mapView,boolean shadow)

   {

//shadow - If true, draw the shadow layer.

//If false, draw the overlay contents.

       if(!shadow)

       {

         //获取mapview的projection对象

       Porjection projection = mapView.getProjection();

 

        Point point = new Point();

        

        //将真实的地理坐标转换为屏幕上的坐标

        projection.toPixels(geopoint,point);

 

        //在指定位置绘制图片 ,注意四个参数

       canvas.drawBitmap(bitmap,

       point.x - bitmap.getWidth() / 2,

       point.y - bitmap.getHeight(),

       null);

     }

   }

}

posted on 2012-08-04 20:52  lightman_21  阅读(168)  评论(0)    收藏  举报

导航