flutter-geolocator icon indicating copy to clipboard operation
flutter-geolocator copied to clipboard

Geolocator.getCurrentPosition() is not returning latitude or longitude.

Open shrishti08 opened this issue 6 years ago • 5 comments

Geolocator.getCurrentPosition() is not working for emulator. However, it is working on a real device.

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

class LoadingScreen extends StatefulWidget {
  @override
  _LoadingScreenState createState() => _LoadingScreenState();
}

class _LoadingScreenState extends State<LoadingScreen> {
  void getLocation() async {
    Position position = await Geolocator.getCurrentPosition(
      desiredAccuracy: LocationAccuracy.low,
    );

    print(position);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: RaisedButton(
          onPressed: () {
            getLocation();
          },
          child: Text('Get Location'),
        ),
      ),
    );
  }
}

This is the code and print(position) is not printing latitudes and longitudes.

shrishti08 avatar Nov 28 '20 15:11 shrishti08

Are you testing on iOS or Android?

B.t.w. make sure you enable location updates on the simulator/ emulator. This can be done in the settings of the simulator/ emulator.

Also the simulator/ emulator doesn't always play nice with LocationAccuracy.low, you could try to move this to a higher level.

mvanbeusekom avatar Dec 01 '20 08:12 mvanbeusekom

I am working on an Android emulator. I don't need to get a high accuracy location so I only requested permission for accessing the coarse location. After I saw @mvanbeusekom's comment I wanted to try LocationAccuracy,high after adding the permission needed which is <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> to the manifest.

However after adding that permission, BOTH low and high accuracy requests worked for me. Interesting.

ibpasaoglu avatar Dec 03 '20 20:12 ibpasaoglu

I will close this issue for now. It is a known issue that the Android emulator doesn't play nice with the COARSE permissions. This is due to the fact that COARSE location tries to triangulate the position based on cellular network, which on the emulator is not available.

mvanbeusekom avatar Dec 04 '20 15:12 mvanbeusekom

It worked fine for me when LocationAccuracy changed to high. Thanks !!

Nagarjuna-09 avatar Aug 31 '21 11:08 Nagarjuna-09

Thanks for info

BahuCivci avatar Mar 02 '22 22:03 BahuCivci