如何在颤动中的当前位置创建圆圈
How to create circle on current location in flutter
我正在研究 flutter project.On,我必须在 google map.Does 上的当前位置画一个圆圈。
我想要这样的flutter
提前致谢。
一种方法是更改标记的图标
mapController.addMarker(MarkerOptions(
position: LatLng(37.4219999, -122.0862462),
icon: BitmapDescriptor.fromAsset('images/circle.png',),
),
);
在 android/ios 上设置适当的权限后,在 google 地图选项上设置 trackCameraPosition: true
和 myLocationEnabled: true
,之后您可以通过以下代码在当前位置添加图像
mapController.addMarker(MarkerOptions(
position: mapController.cameraPosition.target,
icon: BitmapDescriptor.fromAsset('images/circle.png',),
),
);
这是一篇很棒的文章,它解释了您可以使用 Google Maps for Flutter(开发者预览版)插件 article
可以做的所有事情
请记住,google 地图小部件是开发人员预览版,版本为 0.2。在接下来的几个月里,许多事情和能力可能会发生变化。
在 https://github.com/flutter/plugins/pull/1136
处有一个具有此功能的已打开拉取请求
但是 Google 团队没有接受它,因为提交的许可存在问题。不知道会不会合并接受了很多pull request,但是没有集成。
如果你使用flutter_map插件,那么你可以轻松绘制半径圆。这是代码。
FlutterMap(
options: MapOptions(
center: LatLng(latitude, longitude),
zoom: 16.0
),
layers: [
TileLayerOptions(
urlTemplate: "map url",
additionalOptions: {
"accessToken" : "xxx",
"id" : "map id"
}
),
MarkerLayerOptions(
markers: Marker( //marker
width: 25.0,
height: 25.0,
point: LatLng(latitude, longitude),
builder: (context) {
return Container(
child: IconButton(
icon: Icon(Icons.my_location),
iconSize: 25.0,
color: Color(0xff9045f7),
onPressed: () {
print('marker tapped');
},
),
);
}
)
),
CircleLayerOptions(
circles: CircleMarker( //radius marker
point: LatLng(latitude, longitude),
color: Colors.blue.withOpacity(0.3),
borderStrokeWidth: 3.0,
borderColor: Colors.blue,
radius: 100 //radius
)
)
],
),)
此功能现已在 google_maps_flutter 包中提供:
部分例子:
Set<Circle> circles = Set.from([Circle(
circleId: CircleId(id),
center: LatLng(latitude, longitude),
radius: 4000,
)]);
GoogleMap(
mapType: MapType.normal,
myLocationEnabled: true,
myLocationButtonEnabled: true,
initialCameraPosition: initialMapLocation,
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller);
},
onCameraMove: null,
circles: circles,
);
你可以使用google_maps_flutter插件,这里是代码:
circles: Set.from([Circle( circleId: CircleId('currentCircle'),
center: LatLng(position.latitude,position.longitude),
radius: 4000,
fillColor: Colors.blue.shade100.withOpacity(0.5),
strokeColor: Colors.blue.shade100.withOpacity(0.1),
),],),
我正在研究 flutter project.On,我必须在 google map.Does 上的当前位置画一个圆圈。
我想要这样的flutter
提前致谢。
一种方法是更改标记的图标
mapController.addMarker(MarkerOptions(
position: LatLng(37.4219999, -122.0862462),
icon: BitmapDescriptor.fromAsset('images/circle.png',),
),
);
在 android/ios 上设置适当的权限后,在 google 地图选项上设置 trackCameraPosition: true
和 myLocationEnabled: true
,之后您可以通过以下代码在当前位置添加图像
mapController.addMarker(MarkerOptions(
position: mapController.cameraPosition.target,
icon: BitmapDescriptor.fromAsset('images/circle.png',),
),
);
这是一篇很棒的文章,它解释了您可以使用 Google Maps for Flutter(开发者预览版)插件 article
可以做的所有事情请记住,google 地图小部件是开发人员预览版,版本为 0.2。在接下来的几个月里,许多事情和能力可能会发生变化。
在 https://github.com/flutter/plugins/pull/1136
处有一个具有此功能的已打开拉取请求但是 Google 团队没有接受它,因为提交的许可存在问题。不知道会不会合并接受了很多pull request,但是没有集成。
如果你使用flutter_map插件,那么你可以轻松绘制半径圆。这是代码。
FlutterMap(
options: MapOptions(
center: LatLng(latitude, longitude),
zoom: 16.0
),
layers: [
TileLayerOptions(
urlTemplate: "map url",
additionalOptions: {
"accessToken" : "xxx",
"id" : "map id"
}
),
MarkerLayerOptions(
markers: Marker( //marker
width: 25.0,
height: 25.0,
point: LatLng(latitude, longitude),
builder: (context) {
return Container(
child: IconButton(
icon: Icon(Icons.my_location),
iconSize: 25.0,
color: Color(0xff9045f7),
onPressed: () {
print('marker tapped');
},
),
);
}
)
),
CircleLayerOptions(
circles: CircleMarker( //radius marker
point: LatLng(latitude, longitude),
color: Colors.blue.withOpacity(0.3),
borderStrokeWidth: 3.0,
borderColor: Colors.blue,
radius: 100 //radius
)
)
],
),)
此功能现已在 google_maps_flutter 包中提供:
部分例子:
Set<Circle> circles = Set.from([Circle(
circleId: CircleId(id),
center: LatLng(latitude, longitude),
radius: 4000,
)]);
GoogleMap(
mapType: MapType.normal,
myLocationEnabled: true,
myLocationButtonEnabled: true,
initialCameraPosition: initialMapLocation,
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller);
},
onCameraMove: null,
circles: circles,
);
你可以使用google_maps_flutter插件,这里是代码:
circles: Set.from([Circle( circleId: CircleId('currentCircle'),
center: LatLng(position.latitude,position.longitude),
radius: 4000,
fillColor: Colors.blue.shade100.withOpacity(0.5),
strokeColor: Colors.blue.shade100.withOpacity(0.1),
),],),