我正在按照本教程enter link description here的规定,根据地图中的经度和纬度将图标添加到地图中的每个位置:(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));
如果这能帮助,这是调试的结果:
所以请我怎么能纠正我的代码,根据其位置 把图标感谢您的帮助
感谢您的答复,我解决了这个错误通过将我的变量转换为模型类的双打:) – user3821206