多边形未关闭

时间:2016-09-28 20:58:47

标签: java android google-maps polygon

帮助,我试图绘制多边形,我的多边形没有关闭,我的坐标是正确的。最后一点并不与其他点连接以形成多边形。我不确定我做错了什么。感谢

screenshot http://i65.tinypic.com/29c9i89.jpg

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.ZoomButton;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import android.app.AppOpsManager;


 import com.google.android.gms.maps.model.BitmapDescriptorFactory;
 import com.google.android.gms.maps.model.LatLng;
 import com.google.android.gms.maps.model.Marker;
 import com.google.android.gms.maps.model.MarkerOptions;
 import com.google.android.gms.appindexing.Action;
 import com.google.android.gms.appindexing.AppIndex;
 import com.google.android.gms.common.api.GoogleApiClient;
 import com.google.android.gms.maps.model.Polygon;
 import com.google.android.gms.maps.model.PolygonOptions;
 import com.google.android.gms.maps.model.Polyline;
 import com.google.android.gms.maps.model.PolylineOptions;

  import java.util.Map;


 public class MapsActivity extends FragmentActivity implements   OnMapReadyCallback {

private GoogleMap mMap;


@Override
protected void onCreate(Bundle savedinstancestate) {
    super.onCreate(savedinstancestate);
    setContentView(R.layout.activity_maps);

    final Button button1 = (Button) findViewById(R.id.buttonMaps);
    final Button button2 = (Button) findViewById(R.id.buttonMaps2);
    final Button button3 = (Button) findViewById(R.id.buttonMaps3);
    final Button button4 = (Button) findViewById(R.id.buttonMaps4);
    final Button button5 = (Button) findViewById(R.id.buttonMaps5);
    final Button button6 = (Button) findViewById(R.id.buttonMaps6);
    final Button button7 = (Button) findViewById(R.id.buttonMaps7);
    final Button button8 = (Button) findViewById(R.id.buttonMaps8);
    final Button button9 = (Button) findViewById(R.id.buttonMaps9);
    final Button button10 = (Button) findViewById(R.id.buttonMaps10);


    button2.setVisibility(View.INVISIBLE);
    button3.setVisibility(View.INVISIBLE);
    button4.setVisibility(View.INVISIBLE);
    button5.setVisibility(View.INVISIBLE);
    button6.setVisibility(View.INVISIBLE);
    button7.setVisibility(View.INVISIBLE);
    button8.setVisibility(View.INVISIBLE);
    button9.setVisibility(View.INVISIBLE);
    button10.setVisibility(View.INVISIBLE);


    button1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {


            mMap.clear();
            if (button1.isShown()) {

                Polygon polygon = mMap.addPolygon(new PolygonOptions()
                        .add(new LatLng(6.519,3.368),new LatLng(6.520,3.376), new LatLng(6.522, 3.378), new LatLng(6.523,3.382), new LatLng(6.524,3.390), new LatLng(6.524, 3.999),new LatLng(6.523, 3.406),new LatLng(6.520, 3.404),new LatLng(6.518, 3.406),new LatLng(6.516, 3.407),new LatLng(6.511, 3.409), new LatLng(6.509, 3.410),new LatLng(6.504, 3.410), new LatLng(6.501, 3.407), new LatLng(6.497, 3.402),new LatLng(6.494, 3.399),new LatLng(6.492, 3.397),new LatLng(6.487, 3.397),new LatLng(6.484, 3.398),new LatLng(6.481, 3.396),new LatLng(6.477, 3.395),new LatLng(6.475, 3.395),new LatLng(6.472, 3.395),new LatLng(6.468, 3.394),new LatLng(6.467, 3.387),new LatLng(6.463, 3.381),new LatLng(6.467, 3.379),new LatLng(6.468, 3.377),new LatLng(6.469, 3.374),new LatLng(6.468, 3.370),new LatLng(6.467, 3.365),new LatLng(6.472, 3.364),new LatLng(6.475, 3.365),new LatLng(6.478, 3.366),new LatLng(6.479, 3.367),new LatLng(6.481, 3.369),new LatLng(6.481, 3.372),new LatLng(6.481, 3.376),new LatLng(6.480, 3.381),new LatLng(6.482, 3.384),new LatLng(6.519,3.368))
                        .strokeColor(Color.BLUE)
                        .geodesic(true));

                mMap.addMarker(new MarkerOptions().position(new LatLng(6.5084, 3.3842)).title("Lagos Mainland").snippet("My Location").icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_launcher)));
                button2.setVisibility(View.VISIBLE);
                button3.setVisibility(View.VISIBLE);
                button4.setVisibility(View.VISIBLE);
                button5.setVisibility(View.VISIBLE);
                button6.setVisibility(View.VISIBLE);
                button7.setVisibility(View.VISIBLE);
                button8.setVisibility(View.VISIBLE);
                button9.setVisibility(View.VISIBLE);
                button10.setVisibility(View.VISIBLE);



            }
        }

    });

1 个答案:

答案 0 :(得分:0)

正确绘制多边形。 问题在于 new LatLng(6.524,3.999)。如果您为每个LatLng添加标记,您可以观看它。

试试这个并希望它有所帮助。

mMap.addMarker(new MarkerOptions().position(new LatLng(6.524, 3.999)).title("E"));

mMap.addMarker(new MarkerOptions().position(new LatLng(6.519,3.368) ).title("P01"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.520,3.376) ).title("P02"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.522, 3.378)).title("P03"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.523,3.382) ).title("P04"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.524,3.390) ).title("P05"));
//Point far
mMap.addMarker(new MarkerOptions().position(new LatLng(6.524, 3.999)).title("P06")); //point far

mMap.addMarker(new MarkerOptions().position(new LatLng(6.523, 3.406)).title("P07"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.520, 3.404)).title("P08"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.518, 3.406)).title("P09"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.516, 3.407)).title("P10"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.511, 3.409)).title("P11"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.509, 3.410)).title("P12"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.504, 3.410)).title("P13"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.501, 3.407)).title("P14"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.497, 3.402)).title("P15"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.494, 3.399)).title("P16"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.492, 3.397)).title("P17"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.487, 3.397)).title("P18"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.484, 3.398)).title("P19"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.481, 3.396)).title("P20"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.477, 3.395)).title("P21"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.475, 3.395)).title("P22"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.472, 3.395)).title("P23"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.468, 3.394)).title("P24"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.467, 3.387)).title("P25"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.463, 3.381)).title("P26"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.467, 3.379)).title("P27"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.468, 3.377)).title("P28"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.469, 3.374)).title("P29"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.468, 3.370)).title("P30"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.467, 3.365)).title("P31"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.472, 3.364)).title("P32"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.475, 3.365)).title("P33"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.478, 3.366)).title("P34"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.479, 3.367)).title("P35"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.481, 3.369)).title("P36"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.481, 3.372)).title("P37"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.481, 3.376)).title("P38"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.480, 3.381)).title("P39"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.482, 3.384)).title("P40"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.519,3.368) ).title("P41"));