0

I have a WKT Polygon data string coming from the server which looks like this

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

This is a 5 Point Polygon Each Lat,Long Point is separated by a comma, Like WKT Geometry Format

I want to Convert above WKT polygon data to List array of lat-longs, Something like this,

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

Is there any predefined method or function to do this ? Maybe in Google-Maps Utils? or I have to do manual string operations?

GeekWithGlasses
  • 572
  • 2
  • 12
  • 30

1 Answers1

0

This is simple Code I made which did the trick.

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));
                }
GeekWithGlasses
  • 572
  • 2
  • 12
  • 30