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

前端 未结 4 886
别跟我提以往
别跟我提以往 2021-01-12 17:39

I have used the location plugin in the flutter, I can get the latitude and longitude only. How to get the full ad

4条回答
  •  甜味超标
    2021-01-12 18:10

    `
    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}");
    }
    

    `

提交回复
热议问题