2

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?

Yuvarajan
  • 77
  • 1
  • 11
  • 1
    You can not enable it automatically. You should prompt a message then user will turn it on. Take a look at: https://stackoverflow.com/questions/33251373/turn-on-location-services-without-navigating-to-settings-page/33254073 – a.toraby Oct 09 '18 at 11:10
  • Ok. Thanks for your response. – Yuvarajan Oct 10 '18 at 08:36
  • @a.toraby What is the flutter equivalent of the https://stackoverflow.com/questions/33251373/turn-on-location-services-without-navigating-to-settings-page/33254073 ? – TSR Mar 19 '19 at 03:02

2 Answers2

2

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.

CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
  • Ok fine. It's possible to enable location automatically in android older version like android 5.0? – Yuvarajan Oct 10 '18 at 10:00
  • @user9274318 I don't know that, but I think you can't. – CopsOnRoad Oct 10 '18 at 10:09
  • could you please tell me whether System Dialog will works on older version before android 6.0. Its works fine in later version i.e., from android 6.0 – Yuvarajan Oct 10 '18 at 11:28
  • When you run the same code in devices running Android 6.0 and lower what does it do/show? – CopsOnRoad Oct 10 '18 at 16:21
  • I think it won't display system dialog less than Android 6.0 devices. – Yuvarajan Oct 12 '18 at 06:12
  • You can try searching for a solution on the internet regarding that. – CopsOnRoad Oct 12 '18 at 08:23
  • @CopsOnRoad What is the flutter equivalend of https://stackoverflow.com/questions/33251373/turn-on-location-services-without-navigating-to-settings-page/33254073 ? I asked a question here please assist: https://stackoverflow.com/questions/54397823/turn-on-location-services-without-navigating-to-settings-page-flutter-dart – TSR Mar 19 '19 at 03:03
  • @TSR I can definitely help you but right now I am out of office, once I get back there, I will answer yours in case no one had answered. – CopsOnRoad Mar 19 '19 at 10:35
1

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();
  }
}
SardorbekR
  • 1,388
  • 3
  • 18
  • 33