我有来自服务器的WKT Polygon数据字符串,如下所示
POLYGON ((-79.9767 40.4887, -79.9718 40.4885, -79.9717 40.4888, -79.9722 40.4889, -79.9727 40.4883))
这是一个5点多边形每个纬度,长点用逗号分隔,如WKT Geometry Format
我想将WKT多边形数据转换为Lat-longs的List数组,像这样,
List<LatLng> points // I want above latlongs points to be stored inside it.
是否有任何预定义的方法或功能来执行此操作?也许在Google-Maps Utils中?或者我必须进行手动字符串操作?
答案 0 :(得分: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));
}