1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| try (InputStream is = context.getAssets().open(filePath)) { List<AirPortNoFlyEntity> points = parseExcelPoints2(is); addMarkersToMap(baiduMap,points,RADIUS_KM);
} catch (Exception e) { e.printStackTrace(); }
private List<AirPortNoFlyEntity> parseExcelPoints2(InputStream is) throws Exception { try { // 从 assets 读取 JSON 文件 byte[] buffer = new byte[is.available()]; is.read(buffer); is.close(); String json = new String(buffer, StandardCharsets.UTF_8);
// 使用 Gson 解析为 List<Point> return new Gson().fromJson(json, new TypeToken<List<AirPortNoFlyEntity>>() {}.getType()); } catch (Exception e) { e.printStackTrace(); return null; } }
|