gpt4 book ai didi

java - 如何将纬度/经度列表转换为字符串数组?

转载 作者:行者123 更新时间:2023-12-01 11:41:18 24 4
gpt4 key购买 nike

我有一个纬度/经度列表 List<LatLng> points = new ArrayList<>();当我单击 map (我使用的是谷歌地图 v2)时,我使用 points.add(latLng); 添加元素。我的目标是使用以下方法在点之间画线:

 map.addPolyline(new PolylineOptions().add(new LatLng(x, y), new LatLng(x1, y1)).
width(5).color(Color.BLUE));

问题是我不知道如何将纬度/经度列表转换为 String[] ,这样我就可以将每个索引拆分为纬度和经度并遍历数组,使用上面的方法绘制线条。我如何实现这一目标?

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnClose:
this.finish();
break;
case R.id.btnDeleteFile:
deleteFile();
break;
case R.id.btnDrawLines:
drawLines(latLng);
break;
}

}

@Override
public void onMapClick(LatLng latLng) {
drawLines(latLng);
drawIcons(latLng);
try {
savePositions(latLng);

} catch (IOException e) {
e.printStackTrace();
}
}

private void drawLines(LatLng latLng) {

List<LatLng> points = new ArrayList<>();
points.add(latLng);
}

最佳答案

为什么不直接访问经纬度的值?它们是公共(public)最终 double ,并且应该是可访问的。

例如:

LatLng p = new LatLng(x, y); // if you have this point

// you can do this and get the values
String pLat = p.latitude.toString();
String pLong = p.longitude.toString();
// now you can store pLat and pLong in an array of lats and longs.

因此,如果您有一个点数组列表、一个纬度数组列表和一个长数组列表

for (LatLng p : points) {
// get values and store them
listOfLats.add(p.latitude.toString());
listOfLongs.add(p.latitude.toString());
}

现在您已经存储了这些(成对),您可以使用相同的索引 i 来访问不同点的它们。

尽管TBH,我不知道您当前的方法有什么问题 - 它似乎是受支持的方法,并且您不需要获取字符串值,因为函数本身实际上需要一个 LatLng obj ...

编辑:话虽如此,您可以尝试:

map.addPolyline(new PolylineOptions().addAll(points).width(5).color(Color.BLUE));

关于java - 如何将纬度/经度列表转换为字符串数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29498848/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com