我使用的是 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/