question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[iOS] location.getLocation never returns

See original GitHub issue

Describe the bug Future location.getLocation() never returns

Expected behavior return result(any result)

Tested on:

  • iOS, Version 13.3.1, iPhone 6s

Other plugins:

  • No other pugins

Steps to reproduce:

  1. Turn off location services.
  2. Open the app
  3. Try to get location
  4. Go to settings and enable location services
  5. Back to app and try to get location. getLocation never returns!

Example code: Create new flutter project and add location to pub spec. Then use this code in main.dart

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Location location = Location();
  bool _serviceEnabled;
  PermissionStatus _permissionGranted;
  LocationData _locationData;

  void _getLocation() async {
    print('Check if service is enabled');
    _serviceEnabled = await location.serviceEnabled();
    if (!_serviceEnabled) {
      _serviceEnabled = await location.requestService();
      if (!_serviceEnabled) {
        return;
      }
    }

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

    print('Try to get location');
    _locationData = await location.getLocation();
    print(_locationData);
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'Location:',
            ),
            Text(
              _locationData != null
                  ? '${_locationData.toString()}'
                  : 'no location',
              style: Theme.of(context).textTheme.headline6,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _getLocation,
        child: Icon(Icons.location_on),
      ),
    );
  }
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:8
  • Comments:15

github_iconTop GitHub Comments

2reactions
MichaelM97commented, May 1, 2020

Hi all, I believe that your Simulators aren’t working as expected due to there being no location set for it to use. I’ve opened #358 which adds steps on how to do this to the README 😃

1reaction
ZantsuRockscommented, May 15, 2020

I don’t get why this was closed. The issue ocur in real hardware too. (iOS 13) Steps to reproduce:

  1. Disable Location Services
  2. Open the App and instantiate Location()
  3. Check permissions or try to check if service is enabled.
  4. Enable the service.
  5. Go back to App (Don’t matter if the app has permission or you are giving permissions now)
  6. Try to get location
  7. The method NEVER returns.
Read more comments on GitHub >

github_iconTop Results From Across the Web

"getLocation()" never returns · Issue #172 - GitHub
The call gets stuck on the last line of this method, never returning a proper position. I am using library version 2.3.5 with...
Read more >
Flutter Location packages does not return current location on ...
I managed to solve it, if it happens to you check to do not call .getLocation() while a onChangedPosition listener is active.
Read more >
Xamarin IOS location never returns - Microsoft Q&A
I am trying to get the location of the IOS device(real device IOS 14.6, iPhone 11) on a button click and then it...
Read more >
About privacy and Location Services in iOS and iPadOS
Learn how privacy settings and Location Services help protect your personal information on your iPhone, iPad, and iPod touch.
Read more >
How To Get a User's Location with the Geolocator Plugin in ...
You will then need to add permissions to both Android and iOS by editing ... This will create a button with the message...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found