从地址波动中获取坐标 [英] Obtain coordinates from an address flutter

查看:84
本文介绍了从地址波动中获取坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以引导我获取地址波动的坐标吗?

Could someone guide me to get the coordinates of an address in flutter?

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

I need to enter addresses in a text box and get the longitude and latitude of that address

推荐答案


此处创建了一个Input Text Widget,当用户点击它时。

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';

import 'package:flutter_google_places/flutter_google_places.dart';

这篇关于从地址波动中获取坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆