问题描述
我想使用Google Google Maps for Flutter 在Flutter中创建位置选择器标记.通过创建可拖动选项设置为true的标记,可以创建可拖动标记.使用以下代码段.
I want to create a location picker in flutter using google Google Maps for Flutter and it's marker. It's possible to create a dragable marker by creating a marker with dragable option set to true. Using the following code segment.
Widget _buildMap(BuildContext context) {
return GoogleMap(
options: GoogleMapOptions(
cameraPosition: CameraPosition(
target: LatLng(7.2906, 80.6337),
zoom: 7.0,
),
compassEnabled: true,
),
onMapCreated: (controller) {
_mapController = controller;
controller.addMarker(
MarkerOptions(
draggable: true,
flat: false,
position: LatLng(7.2906, 80.6337),
),
);
},
);
}
但是在拖动标记后,我找不到找到标记的新位置的方法.我尝试通过引用MapController
的markers
属性来获取标记的新位置,但是它返回了标记的初始位置.
But I can't find a way to get the new location of the marker after dragging the marker. I tried to get the new location of the marker by referring to markers
attribute of the MapController
but it returns the initial location of the marker.
_mapController.markers.forEach((marker) {
print("Pos: " + marker.options.position.toString())
});
// Prints "Pos: LatLng[7.2906, 80.63369999999998]"
我在这里做错了什么,还是有另一种方法来完成此用例?谢谢.
What am I doing wrong here or is there another way to accomplish this use case? Thank you.
推荐答案
该软件包是开发人员预览的版本0.0.3.直到达到1.0,才考虑将其用于生产工作.同时,您可能会提出问题,以将具体的优先事项告知flutter团队.
That package is a developers preview, version 0.0.3. Don't consider it for production work until it hits 1.0. In the meanwhile, you might file a issue to inform the flutter team of your specific priorities.
这篇关于Google Maps for Flutter-拖动后获取标记的新位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!