[J2ME]如何替换Google Map静态地图自带的Marker

要替换Google Map静态图片中缺省的Marker为您自己的图标,需要使用

javax.microedition.lcdui.Graphics.drawImage(Image img, int x, int y, int anchor)

 

其中anchor为图像在屏幕上的停靠点。

 

 

int

常量

相当(x,y)

 

0或20

Graphics.SOLID

或Graphics.LEFT|Graphics.TOP

图片左上角为(x,y)

 


3

Graphics.DOTTED|Graphics.VCENTER

或Graphics.HCENTER|Graphics.VCENTER

图片中心为(x,y)

6

Graphics.LEFT|Graphics.VCENTER

图片左边中点为(x,y)

10

Graphics.RIGHT|Graphics.VCENTER

图片右边中点为(x,y)

17

Graphics.DOTTED|Graphics.TOP

或Graphics.HCENTER|Graphics.TOP

图片上边中点为(x,y)

24

Graphics.RIGHT|Graphics.TOP

图片右上角为(x,y)

33

Graphics.BOTTOM|Graphics. DOTTED

或Graphics.BOTTOM|Graphics.HCENTER

图片下边中点为(x,y)

36

Graphics.BOTTOM|Graphics.LEFT

图片左下角为(x,y)

40

Graphics.BOTTOM|Graphics.RIGHT

图片右下角为(x,y)

 

 

然后需要把Marker的经纬度转换成屏幕坐标,可以使用如下的函数:

    public static boolean map2screen(double mx,double my,YPoint pt,double cx,double cy,YRect rt,int zoom)
    {
         if(Math.abs(cx-0.00001)<0.0001 && Math.abs(cy-0.00001)<0.0001)
             return false;

         double size = MyMath.pow(2,zoom);
         double spanY  =  360.0/size*rt.width()/256;
         double spanX  =  360.0/size*rt.height()/256;
         pt.y = (int) (((cx - mx) / spanX + 0.5) * rt.height());
         pt.x = (int) (((my - cy) / spanY + 0.5) * rt.width());

         return true;
    }

 

最后在你的Canvas paint函数中绘制这个图标:

 

MyRect rt = new MyRect(0,0,this.getHeight(),this.getWidth());
MyUtils.map2screen(slatitude,slongitude,mypos,latitude,longitude,rt,zoom);
g.drawImage(imgPos, mypos.x, mypos.y, Graphics.BOTTOM|Graphics.DOTTED);

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值