java - 如何将 latlng 数组列表的值传递给多边形
问题描述
我将坐标存储在firebase中。并且始终作为 latlng 类型的数组列表检索。我的问题是如何将坐标数组的值传递给多边形多边形。
这是我尝试过的。
private void DrawPolygon(List<LatLng> array) {
int length = array.size();
// Store a data object with the polygon,
// used here to indicate an arbitrary type.
PolygonOptions poly = new PolygonOptions();
for (int i = 0; i < length; i++) {
poly.add(new LatLng(array.get(i).latitude, array.get(i).longitude));
}
}
在运行时,多边形数组不会被填充。
解决方案
在尝试填充多边形之前,您应该检查数组的有效性。可能是引用数组中的值是空的。
private void DrawPolygon(List<LatLng> array) {
int length = array.size();
// Store a data object with the polygon,
// used here to indicate an arbitrary type.
PolygonOptions poly = new PolygonOptions();
for(int i = 0; i < length; i++){
if(array.get(i).latitude != null &&
array.get(i).longitude != null){
LatLng latLong = new LatLng(array.get(i).latitude,
array.get(i).longitude);
poly.add(latLong);
}
}
推荐阅读
- reactjs - 在 Expo 上的 React Native 项目中如何更好地管理状态?
- c# - 遵循教程后的 AutoFac.Core.DependencyResolutionException
- ios - Swift Json 响应解码
- javascript - 使用 ReactDOM 后 JavaScript 代码不起作用
- docker - Aspnet.core - Docker 文件创建匿名图像
- testing - 是否可以使用 npm 对等依赖项测试流星包?
- swift - 使用设备中的本地图像以成功对其进行分类
- wordpress - 如何在 WordPress 中更改媒体文件上传日期?
- angular - 单向数据绑定不适用于 FullCalendar 和 Angular
- python - Scrapy分页无限