0

我有一个来自服务器的 WKT 多边形数据字符串,看起来像这样

POLYGON ((-79.9767 40.4887, -79.9718 40.4885, -79.9717 40.4888, -79.9722 40.4889, -79.9727 40.4883))

这是一个 5 点多边形,每个纬度、长点用逗号分隔,如WKT 几何格式

我想将以上 WKT 多边形数据转换为经纬度列表数组,像这样,

 List<LatLng> points // I want above latlongs points to be stored inside it.

是否有任何预定义的方法或功能可以做到这一点?也许在 Google-Maps Utils 中?还是我必须手动进行字符串操作?

4

1 回答 1

0

这是我制作的简单代码,它成功了。

List<LatLng> points = new ArrayList<>();

String sa,sa1,sa2,sa3,sa4;

sa = "POLYGON ((-79.97245641541667 40.48834660577806, -79.97186029446311 40.48851795900649, -79.97175971162505 40.48881068642625, -79.97223848593421 40.488938180547926, -79.97245641541667 40.48834660577806))";
               sa1 = sa.replaceAll("POLYGON ","");
               sa2 = sa1.replaceAll("[()]","");
               sa3 = sa2.replaceAll(", ","#");
               sa4 = sa3.replaceAll(" ",",");

                String[] splitString = sa4.split( "#" );

                for ( String point : splitString )
                { 
                     points.add(new LatLng(point));
                }
于 2018-05-30T07:57:33.223 回答