Home > OS >  How to get users location and show it in a container with Flutter?
How to get users location and show it in a container with Flutter?

Time:11-04

I'm trying to develop a flutter app. The idea of the app is to get the location of some users and show it in a container (not in a map).

However, here we have some conditions, for example, my location is the main location of the list of locations and the most important, I can get the distance of the different locations, but I don't know how to show that position and that relations in my device without a map.

I know that with "position library" I can put any element where I want, so, I can tell to Flutter that if my location is the main location, to show a container (positioned a container) in the middle of the screen trying to simulate that I am that container for example. However, if I have another location on the left (around 10 meters of the left of the main location) how I can show it in my device?

CodePudding user response:

I hope this tutorial on medium can help you. you get user's longitude and latitude adress: https://medium.com/@fernnandoptr/how-to-get-users-current-location-address-in-flutter-geolocator-geocoding-be563ad6f66a

I have understood that you don't want to show the informations in a map, so I think this tutorial can be useful.

CodePudding user response:

use this pulugin

https://pub.dev/packages/geolocator,

there is a function that helps you listen current user location

import 'package:geolocator/geolocator.dart';

final LocationSettings locationSettings = LocationSettings(
  accuracy: LocationAccuracy.high,
  distanceFilter: 100,
);
StreamSubscription<Position> positionStream = Geolocator.getPositionStream(locationSettings: locationSettings).listen(
    (Position? position) {
        print(position == null ? 'Unknown' : '${position.latitude.toString()}, ${position.longitude.toString()}');
    });

Using a stateful class you can show this live location in container or any other widget.

  • Related