gpt4 book ai didi

flutter - 从地址抖动中获取坐标

转载 作者:行者123 更新时间:2023-12-03 22:56:50 24 4
gpt4 key购买 nike

有人可以指导我在 flutter 中获取地址的坐标吗?

我需要在文本框中输入地址并获取该地址的经纬度

最佳答案

Here created an Input Text Widget and when user taps on it. This takes to google autocomplete screen, where user inputs the location.


TextFormField(
decoration: new InputDecoration(
border: InputBorder.none,
contentPadding: EdgeInsets.only(left: 15),
hintText: Strings.enter_your_house_number_street_etc,
hintStyle: TextStyle(
fontSize: 14,
color: AppColor.grey,
fontFamily: "Open Sans",
fontWeight: FontWeight.normal
)),
maxLines: 1,
controller: _address,
onTap: ()async{
// then get the Prediction selected
Prediction p = await PlacesAutocomplete.show(
context: context, apiKey: kGoogleApiKey,
onError: onError);
displayPrediction(p);
},
)

Here it is getting the lat and long of entered location.


Future<Null> displayPrediction(Prediction p) async {
if (p != null) {
PlacesDetailsResponse detail = await _places.getDetailsByPlaceId(p.placeId);

var placeId = p.placeId;
lat = detail.result.geometry.location.lat;
long = detail.result.geometry.location.lng;

var address =detail.result.formattedAddress;

print(lat);
print(long);
print(address);

setState(() {
_address.text = address;
});
}
}

import 'package:flutter_google_places/flutter_google_places.dart';

关于flutter - 从地址抖动中获取坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62399236/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com