Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get full address details based on current location's latitude and longitude in Flutter

I have used the location plugin in the flutter, I can get the latitude and longitude only. How to get the full address details. Codes on below.

Future<Map<String, double>> _getLocation() async {
//var currentLocation = <String, double>{};
Map<String,double> currentLocation;
try {
  currentLocation = await location.getLocation();
} catch (e) {
  currentLocation = null;
}
setState(() {
  userLocation = currentLocation;
});
return currentLocation;



}
like image 499
Arun Avatar asked Feb 19 '19 08:02

Arun


People also ask

How do you get a full address 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 I find the current location of an address?

Right-click the blue dot on the map and a context menu will expand. Click “What's here?” on the menu to see your current location's address and latitude/longitude coordinates.


1 Answers

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

_getLocation() async {
GeolocationStatus geolocationStatus = await 
Geolocator().checkGeolocationPermissionStatus();

Position position = await Geolocator()
    .getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
debugPrint('location: ${position.latitude}');


final coordinates = new Coordinates(position.latitude, position.longitude);
debugPrint('coordinates is: $coordinates');

var addresses =
    await Geocoder.local.findAddressesFromCoordinates(coordinates);
var first = addresses.first;
// print number of retured addresses 
debugPrint('${addresses.length}');
// print the best address
debugPrint("${first.featureName} : ${first.addressLine}");
//print other address names
debugPrint(Country:${first.countryName} AdminArea:${first.adminArea} SubAdminArea:${first.subAdminArea}");
// print more address names
debugPrint(Locality:${first.locality}: Sublocality:${first.subLocality}");
}
like image 135
Agidigbi Ayodeji Victor Avatar answered Oct 29 '22 11:10

Agidigbi Ayodeji Victor