Wanted to load markers on maps asynchronously in Xamarin.Android

问题: I am loading google map and then adding markers on map it usually takes 4 to 7 seconds to load the map with markers but i want to improve performance of app so first i just...

问题:

I am loading google map and then adding markers on map it usually takes 4 to 7 seconds to load the map with markers but i want to improve performance of app so first i just want to show the map and in background i want to load markers and apply on map later. i tried so many ways like Task.Run(), Thread(threadStart()),RunonUiThread() nothing is working. RunonUiThread and threadstart is blocking UI and taking more time to load where in Task.Run is not loading the markers on map.

    protected override void OnCreate(Bundle savedInstanceState)
        {
        base.OnCreate(savedInstanceState);
          SetUpMap();
         }


    SetUpMap(){
        if (_map == null)
        {
            Utils.mapFrag = 
         (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map);
            RunOnUiThread(() =>
                {
             //initializing map which is calling IOnMapReady 
                 asynchronously
                    Utils.mapFrag.GetMapAsync(this); 
                });

        }
        else
        {
            LoadMarkersOnMap(_map);
        }

    }

    public void OnMapReady(GoogleMap googleMap)
    {
        _map = googleMap;
        _map.UiSettings.MapToolbarEnabled = false;
        _map.UiSettings.MyLocationButtonEnabled = false;
        _map.UiSettings.ZoomControlsEnabled = false;
        Utils.map = googleMap;
        System.Threading.Tasks.Task.Run(() =>
        {
            LoadMarkersOnMap(_map);
            if (progressDialog != null && progressDialog.IsShowing)
                progressDialog.Dismiss();
        });
  }

 LoadMarkerOnMap(Googlemap _map){
 RunOnUiThread(()=>{
 //here i m getting the list of markers from the database
 and adding it to map 

});

 }

even i tried without putting runonUithread still it is blocking ui or not loading markers properly. sometimes it load markers some times it do not load all markers.


回答1:

Take a look at the Xamarin docs here: Writing Responsive Applications.

  • 发表于 2019-07-07 04:54
  • 阅读 ( 205 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除