我有一些点坐标如下:
-123.118069008,49.2761419674,0 -123.116802056,49.2752350159,0 -123.115385004,49.2743520328,0 -123.114912944,49.2738039982,.............. -123.118069008,49.2761419674,0
请告诉我如何使用C#创建这样的内容:
new google.maps.LatLng(-123.118069008,49.2761419674),
new google.maps.LatLng(-123.116802056,49.2752350159),
.....
new google.maps.LatLng(-123.118069008,49.2761419674)];
如你所见,我需要:
谢谢
答案 0 :(得分:1)
这是我知道的最简单的方法......
var txt = "-123.118069008,49.2761419674,0 -123.116802056,49.2752350159,0 -123.115385004,49.2743520328,0";
var output = new StringBuilder();
foreach (var group in txt.Split(' '))
{
var parts = group.Split(',');
var lat = double.Parse(parts[0]);
var lng = double.Parse(parts[1]);
if (output.Length > 0)
output.AppendLine(",");
output.Append("new google.maps.LatLng("+lat+","+lng+")");
}
MessageBox.Show("["+output+"]");
结果是......
[new google.maps.LatLng(-123.118069008,49.2761419674),
new google.maps.LatLng(-123.116802056,49.2752350159),
new google.maps.LatLng(-123.115385004,49.2743520328)]
答案 1 :(得分:0)
未经测试且未编译,但这应该可以帮助您开始
var items = data.Split(',');
for(int i = 0; i < items.Length; i = i + 2)
{
var lat = int.Parse(items[i].Replace("0-","-"));
var lng = int.Parse(items[i+1]);
}
您需要进行数组边界检查等,希望这仍然有用。