Reputation: 87
I am working on display near stores based on device location.I have enable the permission but unable to turn the location on.
How to enable location service automatically whenever i entered into my application if in off mode.
Whether it can achieved by write a platform channel to enable location on?
Upvotes: 2
Views: 6642
Reputation: 1758
Try this for native dialog window Location plugin
Example:
import 'package:location/location.dart';
var location = Location();
@override
void initState() {
super.initState();
_checkGps();
}
Future _checkGps() async {
if(!await location.serviceEnabled()){
location.requestService();
}
}
Upvotes: 1
Reputation: 267444
Sorry but in Android, you can't turn on the location via code. You can show user a System Dialog and allow them to enable it.
Even Google maps can't turn on location off and on by itself. It asks user to do so.
PS: I don't know about iOS, but I think there also you can't turn on/off by yourself.
Upvotes: 2