我该如何利用Android中一个图形页面KML文件?我该、图形、页面、文件

2023-09-08 09:37:00 作者:不懂我就不要说我变了

我要画一个KML文件转换成一个图形页面。我看了 在互联网上,但我没有找到一个例子,如何做到这一点, 如果有人能举个例子怎么做,它西港岛线是伟大的!

解决方案

不支持KML现在。你可以画迹像W / O KML:

1)制作要求谷歌服务:

 请求:http://maps.googleapis.com/maps/api/directions/output?parameters
信息关于:https://developers.google.com/maps/documentation/directions/
 

2)发送查询请求

3)这样的解析JSON响应:

 的JSONObject的JSONObject;
  ...
JSONArray结果= jsonObject.optJSONArray(路);
JSONObject的路线= results.optJSONObject(0);
JSONArray腿= route.optJSONArray(腿);
的JSONObject腿= legs.optJSONObject(0);
JSONArray步骤= leg.optJSONArray(步);

的for(int i = 0; I< steps.length(); ++ I){
    的JSONObject步骤= steps.optJSONObject(ⅰ);
    JSONObject的startP = step.optJSONObject(START_LOCATION);
    的JSONObject ENDP = step.optJSONObject(END_LOCATION);
    JSONObject的折线= step.optJSONObject(折线);
    字符串连接codedPoints = polyline.optString(分);
    ...
 

4)连接codedPoints 有很多点,你可以去code。通过这样的:Map使用谷歌路线API视图中绘制方向 - 解码折线

5)绘制覆盖是这样的:

 私有类路延伸覆盖{
        私人的ArrayList<的GeoPoint>清单;
        民营涂料粉刷;

        公共道路(ArrayList中<的GeoPoint>列表){
            this.list =新的ArrayList<的GeoPoint>();
            this.list.addAll(名单);
            油漆=新的油漆();
            paint.setColor(Color.MAGENTA);
            paint.setStyle(Paint.Style.STROKE);
            paint.setStrokeWidth(4);
        }

        @覆盖
        公共无效画(油画画布,图形页面图形页面,布尔影子){
            drawPath(图形页面,帆布);
        }

        私人无效drawPath(MapView的MV,帆布油画){
            INT X1 = -1;
            INT Y1 = -1;
            INT×2 = -1;
            INT Y2 = -1;

            点对点=新的点();

            的for(int i = 0; I<则为list.size();我++){
                mv.getProjection()toPixels(list.get(i)中,点)。
                X2 = point.x;
                Y2 = point.y;

                如果(ⅰ大于0){
                    canvas.drawLine(X1,Y1,X2,Y2,漆);
                }

                ,X1 = X2;
                Y1 = Y2;
            }
        }
 
如何利用Eclipse工具打包签名AndroidApk文件

祝你好运!

I have to draw a KML file into a MapView. I looked in the internet but I didn't find an example how to do it, if someone can give an example how to do it it wil be great!

解决方案

KML is not supported now. You can draw trace like that w/o KML :

1) Make request to Google service :

Request : http://maps.googleapis.com/maps/api/directions/output?parameters
Info about : https://developers.google.com/maps/documentation/directions/

2) Send request

3) Parsing JSON response like this :

JSONObject jsonObject;
  ...
JSONArray results = jsonObject.optJSONArray("routes");
JSONObject route = results.optJSONObject(0);
JSONArray legs = route.optJSONArray("legs");
JSONObject leg = legs.optJSONObject(0);
JSONArray steps = leg.optJSONArray("steps");

for (int i=0; i < steps.length(); ++i) {
    JSONObject step = steps.optJSONObject(i);
    JSONObject startP = step.optJSONObject("start_location");
    JSONObject endP = step.optJSONObject("end_location");
    JSONObject polyline = step.optJSONObject("polyline");
    String encodedPoints = polyline.optString("points");
    ...

4) encodedPoints has many points that you can decode by this : Map View draw directions using google Directions API - decoding polylines

5) Draw overlay like this :

private class Road extends Overlay {
        private ArrayList<GeoPoint> list;
        private Paint paint;

        public Road(ArrayList<GeoPoint> list) {
            this.list = new ArrayList<GeoPoint>();
            this.list.addAll(list);
            paint = new Paint();
            paint.setColor(Color.MAGENTA);
            paint.setStyle(Paint.Style.STROKE);
            paint.setStrokeWidth(4);
        }

        @Override
        public void draw(Canvas canvas, MapView mapView, boolean shadow) {
            drawPath(mapView, canvas);
        }

        private void drawPath(MapView mv, Canvas canvas) {
            int x1 = -1;  
            int y1 = -1;
            int x2 = -1;
            int y2 = -1;

            Point point = new Point();

            for (int i=0; i < list.size(); i++) {
                mv.getProjection().toPixels(list.get(i), point);
                x2 = point.x;
                y2 = point.y;

                if (i > 0) {
                    canvas.drawLine(x1, y1, x2, y2, paint);
                }

                x1 = x2;
                y1 = y2;
            }
        } 

Good luck!