You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android端向Parse Server保存GeoPolygon报错111:无效多边形求助

解决Android中Parse Server保存GeoPolygon报错111的问题

我之前也踩过这个坑,给你几个实用的排查方向和解决方案,应该能搞定这个问题:

1. 必须保证Polygon首尾闭合且顶点数≥3

Parse对Polygon的基础要求是至少3个顶点,并且第一个点和最后一个点坐标完全一致,很多时候复制文档代码时容易忽略闭合这一步。举个直观的例子:

// 错误示例:仅3个点未闭合,会触发111错误
List<ParseGeoPoint> points = new ArrayList<>();
points.add(new ParseGeoPoint(30.0, 100.0));
points.add(new ParseGeoPoint(30.0, 101.0));
points.add(new ParseGeoPoint(31.0, 101.0));
ParsePolygon invalidPolygon = new ParsePolygon(points);

// 正确示例:补上第一个点完成闭合
points.add(new ParseGeoPoint(30.0, 100.0));
ParsePolygon validPolygon = new ParsePolygon(points);

2. 检查顶点顺序是否合规

Parse Server的Polygon校验逻辑对顶点顺序有要求:必须是顺时针或逆时针排列的非交叉序列。如果你的点是随机排列甚至出现交叉,就会被判定为无效。
可以先把坐标序列放到GeoJSON校验工具里验证,确认没有交叉点后再写入代码。

3. 核对SDK与Server版本兼容性

部分旧版本的Parse Server和新版本Android SDK存在格式不兼容的情况,比如SDK生成的Polygon数据结构和Server端的校验逻辑不匹配。建议:

  • 将Android Parse SDK升级到最新稳定版
  • 确保Parse Server版本在4.x及以上(更推荐最新稳定版)

4. 排查坐标是否合法

所有ParseGeoPoint的坐标必须符合地理范围:

  • 纬度范围:-90 ~ 90
  • 经度范围:-180 ~ 180
    很容易犯的错误是把经纬度写反(比如把经度当纬度传入),导致坐标超出范围,进而触发无效Polygon报错。

5. 尝试用GeoJSON直接构造Polygon

如果上面的方法都无效,可以试试通过GeoJSON格式直接创建Polygon,这种方式有时能绕过SDK的某些校验限制:

JSONObject geoJson = new JSONObject();
try {
    geoJson.put("type", "Polygon");
    JSONArray coordinates = new JSONArray();
    JSONArray ring = new JSONArray();
    // 注意GeoJSON的坐标顺序是「经度在前,纬度在后」
    ring.put(new JSONArray().put(100.0).put(30.0));
    ring.put(new JSONArray().put(101.0).put(30.0));
    ring.put(new JSONArray().put(101.0).put(31.0));
    ring.put(new JSONArray().put(100.0).put(30.0)); // 首尾闭合
    coordinates.put(ring);
    geoJson.put("coordinates", coordinates);
    ParsePolygon polygon = new ParsePolygon(geoJson);
} catch (JSONException e) {
    e.printStackTrace();
}

内容的提问来源于stack exchange,提问作者Positive-One

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 08:58:54