Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android地图中绘制多边形_Android_Google Maps_Polygon - Fatal编程技术网

在Android地图中绘制多边形

在Android地图中绘制多边形,android,google-maps,polygon,Android,Google Maps,Polygon,我只想要圆,而不是圆的每一点的每一条线。。。您在查看图像时有进一步的解释: 这是我现在正在使用的代码: final View rootView = layoutInflater.inflate(R.layout.fragment_new_alert, paramViewGroup, false); FrameLayout fram_map = (FrameLayout) rootView.findViewById(R.id.fram_map); Button btn_d

我只想要圆,而不是圆的每一点的每一条线。。。您在查看图像时有进一步的解释:

这是我现在正在使用的代码:

    final View rootView = layoutInflater.inflate(R.layout.fragment_new_alert, paramViewGroup, false);
    FrameLayout fram_map = (FrameLayout) rootView.findViewById(R.id.fram_map);
    Button btn_draw_State = (Button) rootView.findViewById(R.id.btn_draw_State);
    isMapMoveable = false; // to detect map is movable

    SupportMapFragment customMapFragment = ((SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map));
    mMap = customMapFragment.getMap();

    btn_draw_State.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            isMapMoveable = !isMapMoveable;
        }
    });

    fram_map.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            float x = event.getX();
            float y = event.getY();

            int x_co = Math.round(x);
            int y_co = Math.round(y);

            Point x_y_points = new Point(x_co, y_co);

            LatLng latLng = mMap.getProjection().fromScreenLocation(x_y_points);

            if (!isMapMoveable) {
                return false;
            }

            int eventaction = event.getAction();
            switch (eventaction) {
                case MotionEvent.ACTION_DOWN:
                    // finger touches the screen
                    if (polyline != null){
                        polyline.setZIndex(0);
                        polyline.remove();
                        val.removeAll(polyline.getPoints());
                    }
                    val.add(latLng);
                case MotionEvent.ACTION_MOVE:
                    // finger moves on the screen
                    val.add(latLng);
                case MotionEvent.ACTION_UP:
                    // finger leaves the screen
                    drawMap();
                    break;
            }
            return true;
        }
    });
    return rootView;
}

public void drawMap() {
    rectOptions = new PolylineOptions();
    rectOptions.addAll(val);
    rectOptions.color(Color.RED);
    rectOptions.width(7);
    polyline = mMap.addPolyline(rectOptions);
}
根据此处找到的代码:


有什么想法吗?:)谢谢

问题是因为开关中缺少中断

fram_map.setOnTouchListener(新视图.OnTouchListener(){
    fram_map.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    float x = event.getX();
                    float y = event.getY();

                    int x_co = Math.round(x);
                    int y_co = Math.round(y);

                    projection = mGoogleMap.getProjection();
                    Point x_y_points = new Point(x_co, y_co);

                    LatLng latLng = mGoogleMap.getProjection().fromScreenLocation(x_y_points);
                    latitude = latLng.latitude;

                    longitude = latLng.longitude;

                    int eventaction = event.getAction();
                    switch (eventaction) {
                        case MotionEvent.ACTION_DOWN:
                            // finger touches the screen

                            if (mMarkerPoints != null) {
                                mMarkerPoints = new ArrayList<>();
                            }
                            mGoogleMap.clear();
                            mMarkerPoints.add(new LatLng(latitude, longitude));

                        case MotionEvent.ACTION_MOVE:
                            // finger moves on the screen
                            mMarkerPoints.add(new LatLng(latitude, longitude));
                            Draw_Map();
                            break;

                        case MotionEvent.ACTION_UP:
                            // finger leaves the screen
                            Draw_Map_polygon();
                            break;
                    }

                    if (Is_MAP_Moveable == true) {
                        return true;
                    } else {
                        return false;
                    }

                }
            });

//----------- for Making Polygone

    public void Draw_Map_polygon() {
            rectOptions = new PolygonOptions();
            rectOptions.addAll(mMarkerPoints);
            rectOptions.strokeColor(Color.RED);
            rectOptions.strokeWidth(5);
            rectOptions.fillColor(Color.parseColor("#40c4c4c4"));
            polygon = mGoogleMap.addPolygon(rectOptions);
            mGoogleMap.getUiSettings().setAllGesturesEnabled(true);

        }

//----------- When Moving your Hand


        public void Draw_Map() {
            mGoogleMap.addPolyline(new PolylineOptions()
                    .addAll(mMarkerPoints)
                    .width(5)
                    .color(Color.RED));
        }
@凌驾 公共布尔onTouch(视图v,运动事件){ float x=event.getX(); float y=event.getY(); int x_co=数学圆(x); int y_co=数学圆(y); projection=mGoogleMap.getProjection(); 点x_y_点=新点(x_co,y_co); LatLng LatLng=mGoogleMap.getProjection()。来自屏幕位置(x_y_点); 纬度=纬度; 经度=经度; int eventaction=event.getAction(); 开关(事件操作){ case MotionEvent.ACTION\u DOWN: //手指触摸屏幕 if(mMarkerPoints!=null){ mMarkerPoints=newarraylist(); } mGoogleMap.clear(); mMarkerPoints.add(新纬度、经度); case MotionEvent.ACTION\u移动: //手指在屏幕上移动 mMarkerPoints.add(新纬度、经度); 绘制地图(); 打破 case MotionEvent.ACTION\u UP: //手指离开屏幕 绘制地图和多边形(); 打破 } if(Is_MAP_Moveable==true){ 返回true; }否则{ 返回false; } } }); //-----------制作多功能手机 公共空间绘制\映射\多边形(){ rectOptions=新的多边形选项(); rectOptions.addAll(mMarkerPoints); strokeColor(Color.RED); 笔划宽度(5); rectOptions.fillColor(Color.parseColor(#40c4c4”); polygon=mGoogleMap.addPolygon(矩形选项); mGoogleMap.getUiSettings().setAllGesturesEnabled(true); } //-----------当你移动你的手 公共空间绘制图(){ mGoogleMap.addPolyline(新的PolylineOptions() .addAll(mMarkerPoints) .宽度(5) .颜色(颜色.红色)); }
您可以将您的答案标记为答案,这将帮助其他人解决相同的问题。是的,我知道,但我只能在24小时后完成,我一直在等待它!)你的保龄球线有边界线吗?我需要边界lat long。我需要清除polygonOptions列表,就像我必须清除所有东西一样,即使是旧latlong列表?