Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从UI线程外部向MKMapView添加注释_C#_.net_Xamarin.ios_Xamarin - Fatal编程技术网

C# 从UI线程外部向MKMapView添加注释

C# 从UI线程外部向MKMapView添加注释,c#,.net,xamarin.ios,xamarin,C#,.net,Xamarin.ios,Xamarin,我正在尝试将地图标记从API显示到MKMapView。我正在Xamarin Studio中为iOS编写代码。我正在调用函数getAllMarkers()我创建的 看起来是这样的: private void getAllMarkers() { var client = new RestClient("http://example.com/"); var request = new RestRequest(String.Format(""));

我正在尝试将地图标记从API显示到MKMapView。我正在Xamarin Studio中为iOS编写代码。我正在调用函数
getAllMarkers()我创建的

看起来是这样的:

private void getAllMarkers()
{
    var client = new RestClient("http://example.com/");
    var request = new RestRequest(String.Format(""));

    client.ExecuteAsync (request, response => {
           JsonValue data = JsonValue.Parse(response.Content);
    for (var i = 0; i < data.Count; i++){
        var store = new BasicMapAnnotation (new CLLocationCoordinate2D(10.00, -1.00), "Shop name", "Extras);
        map.AddAnnotation(store);
     }
   });
}
private void getAllMarkers()
{
var client=新的RestClient(“http://example.com/");
var请求=新的重新请求(String.Format(“”);
client.ExecuteAsync(请求、响应=>{
JsonValue data=JsonValue.Parse(response.Content);
对于(var i=0;i
这给了我以下错误:

如何从函数getAllMarkers()向地图添加标记?

使用()

InvokeOnMainThread ( () => {
    // manipulate UI controls
 `  map.AddAnnotation(store);`
});