flutterlocation icon indicating copy to clipboard operation
flutterlocation copied to clipboard

iOS Simulator "getLocation" not resolving

Open RedHappyLlama opened this issue 4 years ago • 10 comments
trafficstars

Hi,

I had the issue where location.getLocation() was not resolving on iOS simulator.

I've just noticed that the issue only occured when the simulator location settings (Features, Location) were set to Custom Location.... Any other setting it seemed to work fine.

FYI - The Flutter geolocator package works fine with Custom Location...

RedHappyLlama avatar Nov 05 '21 12:11 RedHappyLlama

Same issue.

mrsrmn avatar Nov 07 '21 18:11 mrsrmn

I've noticed this as well, but only an issue for the very first install of the app. After a cold restart, it works when the sim is set to Custom Location.

Expected behavior:

getLocation() retrieves coordinates when iOS sim is set to Custom Location

Actual behavior:

getLocation() hangs indefinitely until a cold restart. After a cold restart coordinates are retrieved as expected.

Minimum reproducible code:

Set an iOS sim to Custom Location and run this code.

import 'package:flutter/material.dart';
import 'package:location/location.dart';

void main() => runApp(const MyApp());

class MyApp extends StatefulWidget {
  const MyApp();

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String lat = 'not initialized';
  String long = 'not initialized';

  Future<void> _fetchLocation() async {
    setState(() {
      lat = 'loading lattitude...';
      long = 'loading longitude...';
    });

    final location = Location();

    bool _serviceEnabled;
    PermissionStatus _permissionGranted;
    LocationData _locationData;

    _serviceEnabled = await location.serviceEnabled();
    if (!_serviceEnabled) {
      _serviceEnabled = await location.requestService();
      if (!_serviceEnabled) {
        return;
      }
    }

    _permissionGranted = await location.hasPermission();
    if (_permissionGranted == PermissionStatus.denied) {
      _permissionGranted = await location.requestPermission();
      if (_permissionGranted != PermissionStatus.granted) {
        return;
      }
    }

    _locationData = await location.getLocation();
    setState(() {
      lat = _locationData.latitude!.toString();
      long = _locationData.longitude!.toString();
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text('Lat: $lat'),
              Text('Long: $long'),
              ElevatedButton(
                onPressed: () => _fetchLocation(),
                child: const Text('Fetch Location'),
              )
            ],
          ),
        ),
      ),
    );
  }
}

BlackCatDev-IO avatar Nov 11 '21 22:11 BlackCatDev-IO

@BlackCatDev-IO Still doesn't work for me. What is your Flutter and location version and which emulator did you use?

mrsrmn avatar Nov 12 '21 11:11 mrsrmn

@MakufonSkifto I'm on Flutter 2.5.3 stable. I experienced the same behavior on an iPhone 12 Pro Max and iPhone 11 simulator.

BlackCatDev-IO avatar Nov 12 '21 14:11 BlackCatDev-IO

@BlackCatDev-IO Still doesn't work for me. The devs needs to fix this as soon as possible.

mrsrmn avatar Nov 14 '21 13:11 mrsrmn

@MakufonSkifto check #549. First 2 locations are ignored. You have to change your custom location a couple of times on order to receive a new location.

sandersaelmans avatar Nov 29 '21 07:11 sandersaelmans

I can confirm the problem can be reproduced with the sample program from the repository, running on a Mac Mini M1, XCode 13.2.1, iPhone 13 simulator (ios 15.2), Flutter 2.8.1. Has anyone come up with a work-around that doesn't require changing the location in the simulator?

abhlabs avatar Jan 23 '22 15:01 abhlabs

Any word on when the potential fixes will be in a new package version?

MarcBritton avatar Feb 22 '22 06:02 MarcBritton

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 16 '22 17:04 stale[bot]

Let's remove the inactive label, because only the maintainer is inactive.

LostInDarkMath avatar Apr 16 '22 17:04 LostInDarkMath