Unable to trigger geojson marker over a google-map android

匿名 (未验证) 提交于 2019-12-03 10:24:21

问题:

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

回答1:

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


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!