0

I am just about to use the "FusedLocationProvider" from the xamarin sample. When I start it up, it works. It is just one activity and one layout file.

I now added a new class to my project and called it "FindTheLocationNEW" into which I simply copy-pasted everything from the xamarin sample. Now, everything seems to work fine after a few adjustments with the layout file (nothing serious) and only the "this" keyword says:

Cannot convert from "FusedLocationProvider.MainActivity" to "Android.App.PendingIntent".

However, this did work when it was a standalone activity. So I am guessing, the "this" keyword is getting a wrong context.

A bit of the code:

namespace FusedLocationProvider
{
    [Activity(Label = "FusedLocationProvider", MainLauncher = true)]
    public class MainActivity : Activity, GoogleApiClient.IConnectionCallbacks,
        GoogleApiClient.IOnConnectionFailedListener, Android.Gms.Location.ILocationListener
    {


            button2.Click += async delegate {
                if (apiClient.IsConnected)
                {
                    button2.Text = "Requesting Location Updates";

                    // Setting location priority to PRIORITY_HIGH_ACCURACY (100)
                    locRequest.SetPriority(100);

                    // Setting interval between updates, in milliseconds
                    // NOTE: the default FastestInterval is 1 minute. If you want to receive location updates more than 
                    // once a minute, you _must_ also change the FastestInterval to be less than or equal to your Interval
                    locRequest.SetFastestInterval(500);
                    locRequest.SetInterval(1000);

                    Log.Debug("LocationRequest", "Request priority set to status code {0}, interval set to {1} ms",
                        locRequest.Priority.ToString(), locRequest.Interval.ToString());

                    // pass in a location request and LocationListener
                    await LocationServices.FusedLocationApi.RequestLocationUpdates(apiClient, locRequest, this); // THIS IS WHERE IT IS NOT WORKING!!!

                    // In OnLocationChanged (below), we will make calls to update the UI
                    // with the new location data
                }
                else
                {
                    Log.Info("LocationClient", "Please wait for Client to connect");
                }
            };
        }

Any help would be awesome!

Anil
  • 1,087
  • 1
  • 11
  • 24
MrMee
  • 143
  • 1
  • 10
  • Likely because `this` refers to something else compared to the class you copied it from. – 0xDEADC0DE Aug 02 '17 at 08:58
  • Please include the source code for `RequestLocationUpdates` in your post. – mjwills Aug 02 '17 at 09:00
  • 1
    The error is somewhat self explanatory. `Cannot convert from "FusedLocationProvider.MainActivity" to "Android.App.PendingIntent".` You are passing a `MainActivity` - the method expects a `PendingIntent`. – mjwills Aug 02 '17 at 09:02
  • hello and thanks: @0xDEADC0DE: How would I find out what it refererred to? – MrMee Aug 02 '17 at 09:04
  • @mjwills: Yes that seems correct. But why did this work before? And what do I need to change? Thank you! – MrMee Aug 02 '17 at 09:05
  • Actually, I am not sure about the "this" keyword. I know it delivers a context... Yes sure, I had the whole code from: https://github.com/xamarin/monodroid-samples/tree/master/FusedLocationProvider It is only 1 activity, and that I fully copied... – MrMee Aug 02 '17 at 09:07

0 Answers0