コード例 #1
0
        private async void OnClickSetMockLocation(object sender, EventArgs eventArgs)
        {
            string Tag = "SetMockLocation";

            //Fill in the information sources such as gps and network based on the application situation.
            Location mockLocation = new Location(LocationManager.GpsProvider);

            mockLocation.Longitude = 34.34;
            mockLocation.Latitude  = 34.34;

            // Note: To enable the mock function, enable the android.permission.ACCESS_MOCK_LOCATION permission in the AndroidManifest.xml file,
            // and set the application to the mock location app in the device setting.
            Task task = fusedLocationProviderClient.SetMockLocationAsync(mockLocation);

            try
            {
                await task;
                if (task.IsCompleted)
                {
                    log.Info(Tag, $"{Tag} is succeeded");
                }
                else
                {
                    log.Error(Tag, $"{Tag} failed: {task.Exception.Message}");
                }
            }
            catch (Exception e)
            {
                log.Error(Tag, $"{Tag} exception: {e.Message}");
            }
        }