-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeoJsonConverter.java
29 lines (26 loc) · 1.07 KB
/
GeoJsonConverter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
* Code for converting Polylines into GeoJSON formatted Strings
* @author Kyungmin Lee
*/
public class GeoJsonConverter {
/**
* Converts the given list of Polylines into a GeoJSON formatted String
*/
public static String convertToGeoJson(List<Polyline> lines) {
StringBuilder builder = new StringBuilder();
builder.append("{ \"type\": \"FeatureCollection\", " +
"\"features\": [");
for (Polyline line : lines) {
builder.append("{ \"type\": \"Feature\", " +
" \"geometry\": { \"type\": \"LineString\", \"coordinates\": ");
List<LatLng> points = line.getPoints();
builder.append(points.toString());
builder.append("}, \"properties\": { \"color\" : \"" + line.getColor() + "\"}");
builder.append("},");
}
// removes the last , at the very end
builder = builder.deleteCharAt(builder.length() - 1);
builder.append("]}");
return builder.toString().replace("lat/lng:", "").replace("(", "[").replace(")", "]");
}
}