google-maps - 如何从 flutter 中的谷歌地图获取位置的纬度和经度坐标?

标签 google-maps flutter geolocation location google-maps-markers

我使用的是 flutter 1.3** 版本,它没有在 GoogleMap() 中定义 markers 语法

GoogleMap(
  onMapCreated: _onMapCreated,
  markers: markers,
)

所以我使用下面的代码尝试从 map 中获取纬度和经度

 void _onMapCreated(GoogleMapController controller){
    this._controller = controller;
    controller.onMarkerTapped.add(_onMarkerTapped);
          }

  void _onMarkerTapped(Marker marker) {
         ...
           }

Widget build(BuildContext context) {
   GoogleMap(
        onMapCreated: _onMapCreated,
        options: GoogleMapOptions(
          ...
        ));
      }

我的问题是如何使用 MarkerOptions 和以上方法将经纬度转换为字符串值?

最佳答案

 LocationData currentLocation;


 getLocation() async {

  var location = new Location();

  location.onLocationChanged().listen((  currentLocation) {

    print(currentLocation.latitude);
    print(currentLocation.longitude);
    setState(() {

        latLng =  LatLng(currentLocation.latitude, currentLocation.longitude);
     });

    print("getLocation:$latLng");

      loading = false;
    });

  }

From this above code, you simply get a Lattitude and longitude and use this latLng variable on

  initialCameraPosition: CameraPosition(
      target: latLng,
      zoom: 17.4746,
    ),

this method in GoogleMap

关于google-maps - 如何从 flutter 中的谷歌地图获取位置的纬度和经度坐标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56070384/

相关文章:

javascript - 如何将文本标签直接放置在 Google map 上

javascript - Chrome Geolocation 通过 HTTP [noS] 访问家庭网络 192.168

ssl - Firefox 地理位置 PERMISSION_DENIED(使用自签名 HTTPS 证书)

dart - 获取到userId后如何使用FutureBuilder?

flutter - 我该如何解决这个弱警告? "The field doesn’ t 覆盖继承的 getter 或 setter。”

android - Worklight - WL.Device.Geo.acquirePosition 或 navigator.geolocation?

javascript - 代码适用于 http ://jsfiddle.net 但不适用于 http ://liveweave. com

r - 映射距离 : controlling for traffic

javascript - MarkerWithLabel - 拖动事件像点击事件一样工作

flutter - 我的水平滚动遇到麻烦- flutter