Home > Net >  my amulator show different location (mountain view) but when i connect my phone it show correct loca
my amulator show different location (mountain view) but when i connect my phone it show correct loca

Time:02-22

getLocation() async {
    print("get location run");
    bool serviceEnabled;

    LocationPermission permission;
    serviceEnabled = await Geolocator.isLocationServiceEnabled();
    if (!serviceEnabled) {
      await Geolocator.openLocationSettings();
      return Future.error('Location services are disabled.');
    }
    permission = await Geolocator.checkPermission();
    if (permission == LocationPermission.denied) {
      permission = await Geolocator.requestPermission();
      if (permission == LocationPermission.denied) {
        return Future.error('Location permissions are denied');
      }
    }
    if (permission == LocationPermission.deniedForever) {
      return Future.error(
          'Location permissions are permanently denied, we cannot request permissions.');
    }
    streamSubscription =
        Geolocator.getPositionStream().listen((Position position) {
      latitude.value = 'Latitude : ${position.latitude}';
      longitude.value = 'Longitude : ${position.longitude}';
      getAdressFromLatLang(position);
    });
  }

  Future<void> getAdressFromLatLang(Position position) async {
    List<Placemark> placemark =
        await placemarkFromCoordinates(position.latitude, position.longitude);
    Placemark place = placemark[0];
    address.value = 'Address: ${place.locality}';
  }

i am in bhopal but it show mountain view. when i run in my android phone it show correct location terminal: I/flutter (19485): Address: Mountain View

CodePudding user response:

You can set the location for emulators manually by clicking the options section in the emulator. Emulators usually show the default location, and we can change it manually.

CodePudding user response:

Emulators show the location of Google Office, California, which is the default one.

In your emulator, go to More button and there you will get the 1st option of Location where you can add the latitude and longitude of the location that you want.

  • Related