折线未显示在google map android

时间:2019-01-28 07:43:46

标签: android native

问题: 我想在Google地图中显示两点之间的折线,我执行了代码,但未显示两点之间的折线,我不知道我在这里犯了什么错误。

这是我的出处:

      @Override
    protected void onPostExecute(List<List<HashMap<String, String>>> result) {



        ArrayList<LatLng> points = null;
        PolylineOptions lineOptions = new PolylineOptions();

        points = new ArrayList<LatLng>();
        MarkerOptions markerOptions = new MarkerOptions();


        for (int i = 0; i < result.size(); i++) {
            points.clear();
            //points = new ArrayList();
            // lineOptions = new PolylineOptions();

            List<HashMap<String, String>> path = result.get(i);

            for (int j = 0; j < path.size(); j++) {
                HashMap<String, String> point = path.get(j);

                double lat = Double.parseDouble(point.get("lat"));
                double lng = Double.parseDouble(point.get("lng"));
                LatLng position = new LatLng(lat, lng);


                points.add(position);

            }

            lineOptions.addAll(points);
            lineOptions.width(12);
            lineOptions.color(Color.RED);
             //mMap.addPolyline(lineOptions);

        }
        if(lineOptions!=null) {
            mMap.addPolyline(lineOptions);
            Toast.makeText(MapsActivity.this, "Passing", Toast.LENGTH_SHORT).show();
        }else{
            Toast.makeText(MapsActivity.this, "Not Passing", Toast.LENGTH_SHORT).show();
        }

输出: enter image description here

0 个答案:

没有答案