Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
482 views
in Technique[技术] by (71.8m points)

flutter - Error in getting full address from coordinates

Hey I have tried some codes to get the full address of a coordinates.. But Iam getting error..

the code is below

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

In this everything is fine except the var first...When I use var first = addresses.first; It is showing error that first is not defined.. Please help me out..

question from:https://stackoverflow.com/questions/65661350/error-in-getting-full-address-from-coordinates

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...