1

I am trying to execute the following code :

          public void OnLocationChanged(Location location) {


        var lat = (TextView)FindViewById<TextView> (Resource.Id.latitude);
        var lon = (TextView)FindViewById<TextView> (Resource.Id.longitude);
        var stName = (TextView)FindViewById<TextView> (Resource.Id.st_name);

        lat.Text = string.Format ("Latitude: {0:N5}",location.Latitude);
        lon.Text = string.Format ("Longitude: {0:N5}", location.Longitude);


        try{
            Geocoder geocode = new Geocoder (this);
            List<Address> getAddrTask = new List<Address>(geocode.GetFromLocation(location.Latitude,location.Longitude,1));
                Address returnedAddress = getAddrTask.FirstOrDefault();
            if(returnedAddress != null){
                System.Text.StringBuilder strReturnedAddress = new StringBuilder();
                for(int i=0; i<returnedAddress.MaxAddressLineIndex;i++){
                    strReturnedAddress.Append(returnedAddress.GetAddressLine(i)).AppendLine(",");
                }
                stName.Text = strReturnedAddress.ToString();
            }
        }
        catch(IOException e){
            Toast.MakeText (this, e.Message, ToastLength.Long).Show ();
        }

    }

it all works great and charming, but when executing it, it gives me on the application output : [Choreographer] Skipped 42 frames! The application may be doing too much work on its main thread.

David Arno
  • 42,717
  • 16
  • 86
  • 131
Izzo32
  • 179
  • 1
  • 4
  • 16

3 Answers3

1

OK if you want to use it as Map you can use this

String locationString = @"http://maps.google.com/maps/api/staticmap?center=" + latitude + "," + longitude + "&zoom=14&size=250x250&maptype=roadmap&markers=color:red%7Clabel:S%7C" + latitude + "," +longitude + "&sensor=false";

                       webBrowser1.Url = new System.Uri(locationString);
Far Fetcher
  • 85
  • 1
  • 5
  • Thanks for reply, but am not using a map in my application. i just want to retrieve the address of my coordinates. – Izzo32 Nov 08 '13 at 19:49
  • Have a look at this http://stackoverflow.com/questions/9409195/how-to-get-complete-address-from-latitude-and-longitude – Far Fetcher Nov 08 '13 at 22:16
0

Geocoder is probably the culprit. Typically it needs to access the Internet to look up the address, and the delay is going to be unpredictable (and could be long enough to cause an Application Not Responding error dialog to pop up).

You should move your try/catch block into an AsyncTask so this task doesn't get run on the main thread. I'm not familiar with Xamarin, but you can look up how to use AsyncTask with it.

Tenfour04
  • 83,111
  • 11
  • 94
  • 154
  • Yea i guess i have to use the AsyncTask and am searching all day about it and how to use it. anyway thanks alot for your reply – Izzo32 Nov 08 '13 at 19:51
0

It's definitely Geocoder that is the culprit. In general, you should perform network tasks in the background so that you don't block the UI thread.

There is a recipe on Xamarin's site on how to use Geocoder in a thread.

Tom Opgenorth
  • 1,511
  • 1
  • 12
  • 19