我正在尝试在setOnFeatureClickListener上获取geojson文件的功能。但是,当我在geojson文件外部或其附近单击时,我遇到了一个问题。我正在其他地方使用。请查看我的代码并向我提出一些建议,以便我可以解决此问题。
private class AsyncGeoJsonLoader extends AsyncTask<Uri , Integer , GeoJsonLayer>{
@Override
protected GeoJsonLayer doInBackground(Uri... uris) {
JSONObject jsonObject = null;
try {
jsonObject = new JSONObject(getStringFromFile(uris[0],getApplicationContext()));
} catch (Exception e) {
e.printStackTrace();
}
return new GeoJsonLayer(_googleMaps, jsonObject);
}
@Override
protected void onPreExecute() {
super.onPreExecute();
a = new ProgressDialog(MainActivity.this);
a.setTitle("Loading File");
File f = new File(GeoJSONFileURL);
a.setMessage(f.getName());
a.show();
}
@Override
protected void onPostExecute(GeoJsonLayer layer) {
super.onPostExecute(layer);
a.dismiss();
if (layer != null) {
layer.addLayerToMap();
layer.setOnFeatureClickListener(new GeoJsonLayer.OnFeatureClickListener() { //Have a look over here.
@Override
public void onFeatureClick(Feature feature) {
String ID = "" ;
if (feature != null) {
ID = feature.getProperty("LINK_ID");
//Save LINK ID
LinkId_Helper.set_LinkID(ID);
if(ID != null)
alertBox("Are you sure want to mark your POI in this location ?" , ID);
else
Toast.makeText(getApplicationContext(),"ID is not available",Toast.LENGTH_SHORT).show();
}
}
});
}else{
Toast.makeText(getApplicationContext(),"No Layer found in this file",Toast.LENGTH_SHORT).show();
}
Toast.makeText(getApplicationContext() , "Layout added to the Map" , Toast.LENGTH_SHORT).show();
}
}
Anyidea将为您带来极大的帮助,因为我在这里遇到障碍。感谢您的关注,