开发者

Draw route from source to destination on MapField

开发者 https://www.devze.com 2023-03-25 06:17 出处:网络
I know I can obtain the coordinates from Google Map services. But how can I get the coordinates for the source and destination to send it to Google Map services, and then draw the route, once I get al

I know I can obtain the coordinates from Google Map services. But how can I get the coordinates for the source and destination to send it to Google Map services, and then draw the route, once I get all the coordinates?

开发者_开发技巧

Edited:

i have something like this :

                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;
                }


You can use a geocoder to get the latitude and longitude of a location. Google has one, documentation at http://code.google.com/apis/maps/documentation/geocoding/.

So after you get directions between the two locations, you'll end up with an XML file that includes directions along with coordinates. Override the MapField's paint() method and use convertWorldToField() to get the locations to draw on the map. From there it's just simply drawing lines from one location to the next.


Google maps does the route calculation for you, no need to do it manually. Use this syntax:

            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);
            } 
0

精彩评论

暂无评论...
验证码 换一张
取 消