【问题标题】:Drawing Polyline between all markers from json request in android在android中的json请求的所有标记之间绘制折线
【发布时间】:2018-10-31 07:28:54
【问题描述】:

我正在 android 中创建一个 hicking 应用程序,到目前为止,我可以在我想要创建的过程中插入各种标记的路径,现在我想在从我的 mysql 数据库获得的标记之间绘制一条折线. 希望能提供一些关于我可以在标记之间画线的最佳方法的指南。

public void getCoordsId(final String id_trilho) {
    RequestQueue requestQueue = Volley.newRequestQueue(MapsActivity.this);
    StringRequest stringRequest = new StringRequest(Request.Method.POST, urlget,
            new Response.Listener<String>() {
                LatLng location;
                @Override
                public void onResponse(String response) {
                    System.out.println(response);
                    Toast.makeText(MapsActivity.this, "boa entrou", Toast.LENGTH_LONG).show();
                    try {
                        JSONArray array = new JSONArray(response);
                        for (int i = 0; i < array.length(); i++) {
                            JSONObject jo = array.getJSONObject(i);

                            Double lat = Double.parseDouble(jo.getString("lat"));
                            Double lng = Double.parseDouble(jo.getString("lon"));
location = new LatLng(lat,lng);
                              MarkerOptions options = new MarkerOptions();
                            options.position(location);
                            mMap.addMarker(options);

                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

基本上我在单击按钮时获得标记,我想知道如何添加线条。

提前感谢您的帮助

【问题讨论】:

    标签: android json maps android-volley polyline


    【解决方案1】:

    首先,您将所有 lat lng 保存在一个数据结构中。假设是ArrayList&lt;LatLng&gt;。然后将它传递给以下函数(基本上是来自this link 的复制粘贴):

    private void createPolylinesFromLatLng(ArrayList<LatLng> list){
        if(myMap != null && list != null && list.size > 0){
            PolylineOptions options = new PolylineOptions().width(5).color(Color.BLUE).geodesic(true);
            for (LatLng z : list) {
                LatLng point = list.get(z);
                options.add(point);
            }
            line = myMap.addPolyline(options);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-23
      • 1970-01-01
      • 2015-04-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多