Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
344 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..


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

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...