[iOS] location.getLocation never returns
See original GitHub issueDescribe 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:
- Turn off location services.
- Open the app
- Try to get location
- Go to settings and enable location services
- 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:
- Created 3 years ago
- Reactions:8
- Comments:15
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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
😃I don’t get why this was closed. The issue ocur in real hardware too. (iOS 13) Steps to reproduce: