Flutter 我怎样才能在颤振图中找到位置?
我正在代码中实现一个映射。到目前为止,这就是我所拥有的:Flutter 我怎样才能在颤振图中找到位置?,flutter,dart,fluttermap,Flutter,Dart,Fluttermap,我正在代码中实现一个映射。到目前为止,这就是我所拥有的: import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_map_tappable_polyline/flutter_map_tappable_polyline.dart'; import 'package:latlong/latlong.dart'; import 'pack
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_tappable_polyline/flutter_map_tappable_polyline.dart';
import 'package:latlong/latlong.dart';
import 'package:geolocator/geolocator.dart';
class MapPicker extends StatefulWidget {
MapPicker({Key key}) : super(key: key);
@override
_MapPicker createState() {
return _MapPicker();
}
}
class _MapPicker extends State<MapPicker> {
Position _position;
void getLocation() async {
var position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
print(position);
setState(() {
_position = position;
});
}
@override
Widget build(BuildContext context) {
if(_position == null)
getLocation();
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text('Escoger Localización'),
),
body: _position != null ? FlutterMap(
options: MapOptions(
center: LatLng(18.0119098, -66.6159138), //Change to _position
zoom: 15.0
),
layers: [
TileLayerOptions(
urlTemplate:
"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
subdomains: ['a', 'b', 'c']),
MarkerLayerOptions(
markers: [],
),
TappablePolylineLayerOptions(
onTap: (TaggedPolyline polyline) => print(polyline.tag)
)
],
)
:
CircularProgressIndicator(),
);
}
}
导入“包装:颤振/材料.省道”;
导入“包:颤振图/颤振图.dart”;
导入“package:flatter_map_tappable_polyline/flatter_map_tappable_polyline.dart”;
导入“包:latlong/latlong.dart”;
导入“包:地理定位器/地理定位器.dart”;
类映射选择器扩展StatefulWidget{
映射选择器({Key}):超级(Key:Key);
@凌驾
_映射选择器createState(){
返回_MapPicker();
}
}
类_映射选择器扩展状态{
位置(u位置),;
void getLocation()异步{
var位置=等待地理定位器。getCurrentPosition(期望精度:定位精度。高);
印刷(职位);
设置状态(){
_位置=位置;
});
}
@凌驾
小部件构建(构建上下文){
如果(_position==null)
getLocation();
返回脚手架(
appBar:appBar(
//在这里,我们从MyHomePage对象中获取由创建的值
//使用App.build方法,并使用它设置appbar标题。
标题:文本(“Escoger Localización”),
),
主体:_位置!=null?映射(
选项:地图选项(
中心:LatLng(18.0119098,-66.6159138),//更改为_位置
缩放:15.0
),
图层:[
TileLayerOptions(
URL模板:
“https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png”,
子域:['a','b','c']),
MarkerLayerProptions(
标记:[],
),
t可调整的多段地层倾角(
onTap:(TaggedPolyline polyline)=>打印(polyline.tag)
)
],
)
:
CircularProgressIndicator(),
);
}
}
我现在正在使用一个set LatLon进行测试,但是我的想法是使用\u position
在打开地图时使用当前位置。但是,我的问题是:我希望能够点击地图上的任何地方,并获得我点击的地方的坐标。这可能吗