简体   繁体   English

如何在颤振地图上获取标记纬度和经度?

[英]How to get marker latitude and longitude on flutter map?

I'm using google_maps_flutter package to display the map and I placed a marker so the user can select a location (not the user location any location on the map).我正在使用 google_maps_flutter 包来显示地图,并放置了一个标记,以便用户可以选择一个位置(而不是用户在地图上的任何位置)。
like this Now the user can drag the marker where he want , my question is 像这样现在用户可以将标记拖到他想要的地方,我的问题是

Can I get latitude and longitude for marker after user drag it?用户拖动标记后,我可以获取标记的纬度和经度吗?

here is my full code 这是我的完整代码

class _BodyState extends State<Body> {
  MapType mapType = MapType.normal;
  Completer<GoogleMapController> _controller = Completer();
  LocationServices _locationServices;
  LocationData _locationData;
  CameraPosition _cameraPosition;
  Set<Marker> allMapMarkers;
  Marker userPicker;

  @override
  Widget build(BuildContext context) {
    _locationServices=Provider.of<LocationServices>(context);

    return FutureBuilder(
      future: _locationServices.getLocation().then((LocationData value) => _locationData=value),
      builder:(context,snapshot){
        if(_locationData==null){
         return Center(child: CircularProgressIndicator());
        }else{
          _cameraPosition=CameraPosition(target:LatLng(_locationData.latitude,_locationData.longitude),zoom: 19);
          setupMarkers();   // this set the Lat and Long for marker 
          return SafeArea(
            child: Stack(
              children: [
                GoogleMap(
                  onMapCreated: (GoogleMapController controller) {
                    _controller.complete(controller);
                  },
                  initialCameraPosition: _cameraPosition,
                  mapType: mapType,
                  compassEnabled: false,
                  zoomControlsEnabled: false,
                  markers: allMapMarkers,
                ),

You can use the Marker from google_maps_flutter plugin to fetch marker coordinates.您可以使用google_maps_flutter插件中的标记来获取标记坐标。 It has an onDrag property that returns a LatLng object that contains coordinates.它有一个onDrag属性,该属性返回一个包含坐标的LatLng对象。 Use the onDragEnd property to fetch the coordinates on where the marker has been placed.使用onDragEnd属性获取放置标记的坐标。

Marker(
  onTap: () {
    debugPrint('Tapped');
  },
  draggable: true,
  markerId: MarkerId('Marker'),
  onDragEnd: ((LatLng newPosition) {
    debugPrint(newPosition.latitude);
    debugPrint(newPosition.longitude);
  }),
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在颤振应用程序中集成地图并获取用户在地图上设置的标记纬度和经度? - How to Integrate Map in flutter Application and get marker latitude and longitude which user set on map? 如何在颤振中获得纬度和经度 - How to get latitude and longitude in flutter 在 map 中点击某处后如何从 flutter_map 获取经度和纬度? - How to get longitude and latitude from flutter_map after tapping somewhere in the map? 如何在 google_maps_flutter 中获取当前的纬度和经度? - How to get current latitude & longitude in google_maps_flutter? Flutter 如何使用地理定位器 package 获取纬度、经度? - Flutter how to get latitude, longitude using geolocator package? 如何使用点击地点的纬度和经度获取 Flutter 中地点的自动完成位置? - How to get autocomplete location of places in Flutter with Latitude and Longitude of tapped place? Flutter 如何从 api 响应中获取所有经纬度 - Flutter how to get all latitude and longitude from api response 无法获取经纬度用户-Flutter - Unable to get latitude and longitude user - Flutter 如何在颤振地图上获得标记lat和long? - How to get marker lat and long on flutter map? 如何使用位置在颤动中转换纬度和经度 - how to convert latitude and longitude in flutter using location
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM