(google map android)在geojson图层的顶部添加多个标记

时间:2018-05-16 00:44:50

标签: android google-maps google-maps-markers geojson

我正在尝试将突出显示上面的geojson图层的标记,但我无法添加多个标记。我玩过zIndex,但它似乎不起作用 这是我的添加标记和geojson代码:

mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
        @Override
        public void onMapClick(LatLng latLng) {
            try {
                Geocoder gc = new Geocoder(ScratchmapActivity.this, Locale.getDefault());
                List<Address> addrs = null;
                addrs = gc.getFromLocation(latLng.latitude, latLng.longitude, 2);
                String country =addrs.get(0).getCountryName();
                zInd++;
                mMap.addMarker(new MarkerOptions().position(latLng).title(
                    "aloha").zIndex(zInd));

            }catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    });


public void addGeoJsonLayer(int color, int resource){

    try {
        GeoJsonLayer layer = new GeoJsonLayer(mMap, resource, getApplicationContext());

        GeoJsonPolygonStyle style = layer.getDefaultPolygonStyle();
        style.setFillColor(color);
        style.setStrokeColor(color);
        style.setStrokeWidth(1F);
        style.setZIndex((float) 1);

        layer.addLayerToMap();

    } catch (IOException ex) {
        Log.e("IOException", ex.getLocalizedMessage());
    } catch (JSONException ex) {
        Log.e("JSONException", ex.getLocalizedMessage());
    }

}

enter image description here

1 个答案:

答案 0 :(得分:0)

回答这个问题似乎很晚,但是我遇到了同样的问题,我通过使用封闭的线串而不是多边形来解决了这个问题。

    val listPoints = mutableListOf<LatLng>() 
    listPoints.addAll(vertices)
    listPoints.add(vertices.first())
    val gsLineString = GeoJsonLineString(listPoints)
相关问题