在MapField上绘制从源到目标的路径

时间:2011-08-05 06:55:57

标签: blackberry blackberry-maps

我知道我可以从Google地图服务中获取坐标。但是,如果获得所有坐标,我如何获取源和目标的坐标以将其发送到Google地图服务,然后绘制路线?

编辑:

我有这样的事情:

                bmp = new Bitmap(getWidth(), getHeight());
                bmp.createAlpha(Bitmap.ALPHA_BITDEPTH_8BPP);
                Graphics g = Graphics.create(bmp);
                int x1 = -1, y1 = -1, x2 = -1, y2 = -1;
               XYPoint point0 = new XYPoint();
                convertWorldToField(mPoints[0], point0);
                x1=point0.x;
                y1=point0.y;
                g.setColor(Color.BLUE);
                g.fillEllipse(x1, y1, x1, y1 + 1, x1 + 1, y1, 0, 360);

                for (int i = 0; i < mPoints.length; i++) {
                        XYPoint point = new XYPoint();
                        convertWorldToField(mPoints[i], point);
                        x2 = point.x;
                        y2 = point.y;
                        g.setColor(Color.GREEN);
                        g.drawLine(x1, y1, x2, y2);
                        g.fillEllipse(x1, y1, x1, y1 + 1, x1 + 1, y1, 0, 360);
                if(i == mPoints.length-1)
                        {
                            g.setColor(Color.YELLOWGREEN);
                            g.fillEllipse(x1, y1, x1, y1 + 1, x1 + 1, y1, 0, 360);
                        }
                        x1 = x2;
                        y1 = y2;
                }

2 个答案:

答案 0 :(得分:0)

您可以使用地理编码器获取某个位置的纬度和经度。 Google在http://code.google.com/apis/maps/documentation/geocoding/有一个文档。

因此,在获得两个位置之间的路线后,您将得到一个包含方向和坐标的XML文件。覆盖MapField的paint()方法并使用convertWorldToField()获取要在地图上绘制的位置。从那里,它只是简单地从一个位置到下一个位置画线。

答案 1 :(得分:0)

Google地图为您执行路线计算,无需手动执行。使用以下语法:

            double xPos = GPSListener.handle().getLocation().getLatitude();
            double yPos = GPSListener.handle().getLocation().getLongitude();
            String sourceAddr = xPos + "," + yPos;
            int moduleHandle = CodeModuleManager.getModuleHandle("GoogleMaps");
            if (moduleHandle != 0) {
                String[] args = { "http://gmm/x?action=ROUT&start=" + sourceAddr + "&end=" + lat + "," + longi };
                ApplicationDescriptor ad = new ApplicationDescriptor(CodeModuleManager.getApplicationDescriptors(moduleHandle)[0], args);
                ApplicationManager.getApplicationManager().runApplication(ad, true);
            } 
相关问题