Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.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# Android更新谷歌地图间隔后_C#_Android_Google Maps_Xamarin_Xamarin.android - Fatal编程技术网

C# Android更新谷歌地图间隔后

C# Android更新谷歌地图间隔后,c#,android,google-maps,xamarin,xamarin.android,C#,Android,Google Maps,Xamarin,Xamarin.android,我必须在间隔后(比如10秒)用新的位置更新谷歌地图标记。纬度和经度的值每10秒来自web服务 我使用定时器和下面的代码。它工作正常,但使用定时器时,它会在摄像机前崩溃,如下所示: private void OnTimedEvent(object sender, GoogleMap googleMap) { // return; double latitude = Convert.ToDouble((FindViewById<EditText>(Resou

我必须在间隔后(比如10秒)用新的位置更新谷歌地图标记。纬度和经度的值每10秒来自web服务

我使用定时器和下面的代码。它工作正常,但使用定时器时,它会在摄像机前崩溃,如下所示:

private void OnTimedEvent(object sender, GoogleMap googleMap) 
{    
    //   return;
    double latitude = Convert.ToDouble((FindViewById<EditText>(Resource.Id.txtLatitude)).Text);
    double longitude = Convert.ToDouble((FindViewById<EditText>(Resource.Id.txtLongitude)).Text);
    this.GMap = googleMap;

    LatLng latlng = new LatLng(Convert.ToDouble(latitude), Convert.ToDouble(longitude));
    CameraUpdate camera = CameraUpdateFactory.NewLatLngZoom(latlng, 15);
    this.GMap.MoveCamera(CameraUpdateFactory.NewLatLng(latlng)); // it crashes here             
}

Google关于
GoogleMap
以及引发异常的方法的说明:

注意:…GoogleMap只能从主线程读取和修改从另一个线程调用GoogleMap方法将导致异常

将GoogleMap调用包装在
RunOnUiThread
调用中:

        RunOnUiThread(() =>
        {
            this.GMap.MoveCamera(CameraUpdateFactory.NewLatLng(latlng));            
        });

Ref:

请将实际异常添加到您的问题中。我看到此异常:Java.Lang.IllegalStateException:不在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()的主线程上
        RunOnUiThread(() =>
        {
            this.GMap.MoveCamera(CameraUpdateFactory.NewLatLng(latlng));            
        });