gpt4 book ai didi

c# - 当影响经度、纬度到位置时,输入字符串的格式不正确

转载 作者:太空宇宙 更新时间:2023-11-03 23:22:33 26 4
gpt4 key购买 nike

我正在学习本教程 enter link description here根据此 Web 服务的经度和纬度将图标添加到 map 中的每个位置:(json 格式)

{
success: 1,
total: 2,
locals: [
{
id_local: "59",
local_longi: "20",
local_latit: "25894"
},
{
id_local: "60",
local_longi: "10.33699",
local_latit: "25.997745"
}
]
}

这是我的代码:

private async void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
{
await
this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(
async () =>
{
UriS = "MyURL";
var http = new HttpClient();
http.MaxResponseContentBufferSize =Int32.MaxValue;
var response = await http.GetStringAsync(UriS);
var rootObject = JsonConvert.DeserializeObject<NvBarberry.Models.RootObject>(response);

for(int i=0;i< int.Parse(rootObject.total); i++)
{
//Get the current location
Location[] location = new Location[2];
location[i] = new Location(double.Parse(rootObject.locals[i].local_latit), double.Parse(rootObject.locals[i].local_longi)); //I get the error here

//Update the position of the GPS pushpin
MapLayer.SetPosition(GpsIcon, location[i]);

//Set the radius of the Accuracy Circle
GpsIcon.SetRadius(args.Position.Coordinate.Accuracy);

//Make GPS pushpin visible
GpsIcon.Visibility = Windows.UI.Xaml.Visibility.Visible;

//Update the map view to the current GPS location
MyMap.SetView(location[i], 17);

}
}));
}

我收到这个错误:

Input string was not in a correct format

在这一行:

location[i] = new Location(double.Parse(rootObject.locals[i].local_latit), double.Parse(rootObject.locals[i].local_longi));

如果这有帮助,这是调试的结果:

enter image description here

所以请问我如何更正我的代码,根据它的位置放置图标感谢帮助

最佳答案

调试查看rootObject.locals[i].local_latitrootObject.locals[i].local_longi是什么地方报错。如果它们最终为 null 而不是声明的字符串,则会引发此错误。

关于c# - 当影响经度、纬度到位置时,输入字符串的格式不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34904876/

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