Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get location name from coordinates in flutter?

Tags:

flutter

dart

I wanted a button that can get the location of the user and display the place name using GPS.

I tried map_view but it only can get latitude and longitude.

like image 407
Daniel Mana Avatar asked Apr 10 '18 14:04

Daniel Mana


People also ask

How do you get the location name from latitude and longitude in Flutter?

Get user's latitude and longitude To query the current location of the device, simply make a call to the getCurrentPosition() method. For example: import 'package:geolocator/geolocator. dart';Position position = await Geolocator.

How do you access location in Flutter?

Get the user's locationIn your screen's dart file, import the library. import 'package:geolocator/geolocator. dart'; Create variables for storing the position and the address, in the state class.

How do you get a user's location with the Geolocator plugin in Flutter?

Open AndroidManifest. xml in your code editor and add one of the following. ACCESS_FINE_LOCATION is the most precise, whereas ACCESS_COARSE_LOCATION gives results equal to about a city block. With this setup complete, you can create the widget that will trigger and display the user's current location.


1 Answers

use the geocoder plugin it provide you a findAddressesFromCoordinates

import 'package:geocoder/geocoder.dart';

example;

final coordinates = new Coordinates(1.10, 45.50);
addresses = await Geocoder.local.findAddressesFromCoordinates(coordinates);
first = addresses.first;
print("${first.featureName} : ${first.addressLine}");

NOTE: you can also use geolocation plugin to get a lot of useful information like Retrieving last known location

like image 131
Raouf Rahiche Avatar answered Nov 17 '22 02:11

Raouf Rahiche