Rob*_*bot 1 java android google-maps
我在String中有latlng值.我想将该String转换为LatLng对象.喜欢LatLng latlng = new LatLng(lat, lng);
这是我的数据:
String latlan ="
[[13.041695199971244, 77.61311285197735],
[13.042000923637021, 77.61313531547785],
[13.041830750574812, 77.61335827410221],
[13.041507062142946, 77.61269208043814]]
";
Run Code Online (Sandbox Code Playgroud)
提前致谢
解析您的数据如下:
List<LatLng> coordinates = new ArrayList<>();
try {
JSONArray jsonArray = new JSONArray(latlan);
for (int i = 0; i < jsonArray.length(); i++) {
JSONArray latLong = jsonArray.getJSONArray(i);
double lat = latLong.getDouble(0);
double lon = latLong.getDouble(1);
coordinates.add(new LatLng(lat, lon));
}
} catch (JSONException e) {
e.printStackTrace();
}
System.err.println(Arrays.toString(coordinates.toArray()));
for (LatLng latLng : coordinates) {
//use the coordinates.
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
970 次 |
最近记录: |