【问题标题】:(google map android) add multiple markers on top of of a geojson layer(google map android)在geojson层的顶部添加多个标记
【发布时间】:2018-05-16 00:44:49
【问题描述】:

我正在尝试在上面高亮显示 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

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2016-06-22
      • 1970-01-01
      • 2020-12-25
      • 2014-12-24
      • 1970-01-01
      • 2017-05-18
      • 1970-01-01
      • 1970-01-01
      • 2020-10-06
      相关资源
      最近更新 更多