Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
shrishti08 opened this issue Nov 28, 2020 · 5 comments
Closed
Labels
status: closed (missing info) Indicates the issue was automatically closed due to a lack of information.

Comments

@shrishti08
Copy link

shrishti08 commented Nov 28, 2020

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.

@mvanbeusekom
Copy link
Member

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 mvanbeusekom added the status: needs more info We need more information before we can continue work on this issue. label Dec 1, 2020
@ibpasaoglu
Copy link

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.

@mvanbeusekom
Copy link
Member

mvanbeusekom commented Dec 4, 2020

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.

@Nagarjuna-09
Copy link

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

@BahuCivci
Copy link

Thanks for info

@mvanbeusekom mvanbeusekom added status: closed (missing info) Indicates the issue was automatically closed due to a lack of information. and removed status: needs more info We need more information before we can continue work on this issue. labels Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: closed (missing info) Indicates the issue was automatically closed due to a lack of information.
Projects
None yet
Development

No branches or pull requests

5 participants