Use InvokeOnMainThread()
InvokeOnMainThread ( () => {
// manipulate UI controls
` map.AddAnnotation(store);`
});
Question
I'm trying to display map markers from a API to my MKMapView. I'm coding inside Xamarin Studio for iOS. I'm calling the function getAllMarkers();
that I've created.
Which looks like this:
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);
}
});
}
This gives me the following error:
How can I add markers to the map from my function getAllMarkers()?
Solution
Use InvokeOnMainThread()
InvokeOnMainThread ( () => {
// manipulate UI controls
` map.AddAnnotation(store);`
});