无法通过google-map android触发geojson标记 [英] Unable to trigger geojson marker over a google-map android

查看:167
本文介绍了无法通过google-map android触发geojson标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Google地图android应用上显示一个geojson文件作为图层。一切正常,但我无法触发点击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(){

code>

我得到:

 无法解析方法'setOnFeatureClickListener()'

这是我在onPostExecute中的代码;

  @Override 
protected void onPostExecute(JSONObject jsonObject){
if(jsonObject!= null){
//创建一个新的GeoJsonLayer,将下载的GeoJSON文件传递为JSONOb ject
mLayer = new GeoJsonLayer(map,jsonObject);
//将图层添加到地图上
addColorsToMarkers();
mLayer.addLayerToMap();

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

}
});


$ / code>

我需要添加其他内容吗?



有什么建议吗?
Thanks

解决方案

当我使用compile project(':library')时,我有同样的错误,来样示项目,它工作正常。但如果我使用
编译'com.google.maps.android:android-maps-utils:0.4+',那么错误



原因是可点击的geojson功能非常新,2016年6月9日发布。
所以它尚未更新到0.4.3以上的库中。这就是为什么。
2016年6月9日新增可点击的geojson功能


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

首先,您将从示例库中创建一个jar文件。第二,将lib.jar文件复制到你的项目中。



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

 依赖关系{
compile project(':library')
//或者,从Maven获取:
//编译'com.google.maps.android:android-maps-utils:0.4+ '
compile'c​​om.google.android.gms:play-services-maps:9.4.0'
}


I'm showing a geojson file as a layer over a google map android app. Everything works ok, but I'm not be able to trigger on click in geojson markers.

I have adapted the code in: https://github.com/googlemaps/android-maps-utils/blob/master/demo/src/com/google/maps/android/utils/demo/GeoJsonDemoActivity.java

but in line 142:

layer.setOnFeatureClickListener(new GeoJsonLayer.GeoJsonOnFeatureClickListener() {

I get:

cannot resolve method 'setOnFeatureClickListener()'

This is my code in 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) {

                    }
                });
            }
        }

Do I need to add something else?

Any suggestions? Thanks

解决方案

I had the same error, when I use compile project(':library'), which is come with sample project, it works fine. But if I use compile 'com.google.maps.android:android-maps-utils:0.4+' , it error

the reason is clickable geojson feature is very new, comes out on Jun 9, 2016. So it has not yet been update into above 0.4.3 library. That is why. the new clickable geojson feature just added on Jun 9, 2016

So the work around is to manually use sample library project into your own project, this is a very hard part, I had try 5 hours to make it work.

first, you will make a jar file out of sample library.

second, copy the lib.jar file to your project.

third, reference the jar file from your project, done

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'
}

这篇关于无法通过google-map android触发geojson标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆