【问题标题】:Unable to trigger geojson marker over a google-map android无法通过 google-map android 触发 geojson 标记
【发布时间】:2016-08-16 20:00:19
【问题描述】:

我将 geojson 文件显示为 google map android 应用程序上的一个层。一切正常,但我无法在点击 geojson 标记时触发。

我已将代码改编为: https://github.com/googlemaps/android-maps-utils/blob/master/demo/src/com/google/maps/android/utils/demo/GeoJsonDemoActivity.java

但在第 142 行:

layer.setOnFeatureClickListener(new GeoJsonLayer.GeoJsonOnFeatureClickListener() {

我明白了:

cannot resolve method 'setOnFeatureClickListener()'

这是我在 onPostExecute 中的代码;

 @Override
        protected void onPostExecute(JSONObject jsonObject) {
            if (jsonObject != null) {
                // Create a new GeoJsonLayer, pass in downloaded GeoJSON file as JSONObject
                mLayer = new GeoJsonLayer(map, jsonObject);
                // Add the layer onto the map
                addColorsToMarkers();
                mLayer.addLayerToMap();


                mLayer.setOnFeatureClickListener(new GeoJsonLayer.GeoJsonOnFeatureClickListener() {
                    @Override
                    public void onFeatureClick(GeoJsonFeature feature) {

                    }
                });
            }
        }

我需要添加其他内容吗?

有什么建议吗? 谢谢

【问题讨论】:

    标签: android google-maps geojson


    【解决方案1】:

    我遇到了同样的错误,当我使用示例项目附带的 compile project(':library') 时,它工作正常。但是如果我使用 编译 'com.google.maps.android:android-maps-utils:0.4+' ,报错

    原因是可点击的 geojson 功能非常新,于 2016 年 6 月 9 日推出。 所以它还没有更新到 0.4.3 以上的库中。因此。 the new clickable geojson feature just added on Jun 9, 2016

    所以解决方法是手动将示例库项目使用到您自己的项目中,这是一个非常困难的部分,我尝试了 5 个小时才使其工作。

    首先,您将从示例库中创建一个 jar 文件。

    其次,将 lib.jar 文件复制到您的项目中。

    第三,从你的项目中引用jar文件,完成

    dependencies {
    compile project(':library')
    // Or, fetch from Maven:
    //compile 'com.google.maps.android:android-maps-utils:0.4+'
    compile 'com.google.android.gms:play-services-maps:9.4.0'
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-12
      • 1970-01-01
      相关资源
      最近更新 更多