Flutter从谷歌地图获取坐标

问题描述 投票:1回答:3

我使用包google_maps_flutter在我的应用程序中使用谷歌地图。我的问题是如何设置一个监听器,当我按下地图以显示这个地方的协调时显示。我在文档中找不到任何内容。我发现唯一的东西是controllerMap,我用来设置标记监听器,它有一个方法,.addListener(listener)

任何的想法?

google-maps dart flutter
3个回答
3
投票

我使用下面的onMarkerTapped回调方法解决了这个问题:

注意:下面的mapController是GoogleMap Controller的一个实例

 mapController.**onMarkerTapped**.add((marker){

      String title= marker.options.infoWindowText.title;
      String latitude= marker.options.position.latitude.toString();
      String longitude= marker.options.position.longitude.toString();

  });

2
投票

谷歌地图插件有很多错误:),我更喜欢使用这个插件:flutter_map

完整的例子:

import 'package:location/location.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong/latlong.dart';

class ContactPage extends StatefulWidget {
  @override
  ContactPageState createState() => new ContactPageState();
}

class ContactPageState extends State<ContactPage>
    with TickerProviderStateMixin {


  static LatLng myLocation = new LatLng(51.5, -0.09);
  @override
  void initState() {
    super.initState();
    setState(() {
      new LatLng(51.5, -0.09);
    });
  }

  @override
  Widget build(BuildContext context) {
    Size screenSize = MediaQuery.of(context).size;
    double heigh = screenSize.height;
    TextStyle whiteStyle = new TextStyle(fontSize: 20.0, color: Colors.white);
    return new Directionality(
      textDirection: TextDirection.rtl,
      child: new Container(
          padding: new EdgeInsets.only(bottom: 10.0, left: 1.0, right: 1.0),
          color: Colors.white,
          child: new FlutterMap(
            options: new MapOptions(
                center: myLocation,
                zoom: 15.0,
                maxZoom: 15.0,
                minZoom: 3.0,
                onTap: _handleTap),
            layers: [
              new TileLayerOptions(
                  urlTemplate:
                      "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
                  subdomains: ['a', 'b', 'c']),
              new MarkerLayerOptions(markers: markers)
            ],
          )
          )),
    );
  }
  _handleTap(LatLng point) {
    setState(() {
      myLocation = point;
    });
  }
}

1
投票

此功能目前在google flutter插件的2.0版本中不可用,但是有两个拉取请求已添加此功能。

拉请求1121具有关于如何使用抽头功能的示例代码。

© www.soinside.com 2019 - 2024. All rights reserved.