I need to create polygons on the Google map dynamically in flutter. I could plot polygons with known points but I couldn't draw the polygons dynamically Please help...
I also need to draw a polygon point by point.
To do this, in the onTap handler
GoogleMap(
polygons: Set<Polygon>.of(mapsPolygons.values),
onTap: tapMap,
...
)
I add a marker and write each tap down to the List<LatLng>.
Then I update the map, with the rendered polygon
Map<PolygonId, Polygon> mapsPolygons = <PolygonId, Polygon>{};
List<LatLng> mapsPolygons = [];
void tapMap(LatLng pos) {
final PolygonId polygonId = PolygonId("Polgon_1");
final Polygon polygon = Polygon(
polygonId: polygonId,
strokeColor: Colors.red,
strokeWidth: 5,
fillColor: Colors.red.withOpacity(0.3),
points: polygonPoints,
);
mapsPolygons[polygonId] = polygon;
//setState((){});
}
i update the map using StreamBuilder() but it should work with setState() too
example
P.S. Sorry for my English
Related
enter image description hereI have created a 430-radius circle on Google Maps.
I want one functionality when I click outside of the circle radius then the message shows you are out of the zone.
If I clicked within the circle then I want to show the message you are in your zone.
I have created a 430-radius circle on Google Maps and I compared the latitude and longitude of my current location.
In OnTap I have shown on e Toast message you are in your zone.
The problem is when I press out of the circle the message shows you are in your zone.
Same when I clicked within the circle same message showed.
I have used the if-else statement but I can't achieve the functionality which I want.
final List _list = [
Marker(
markerId: MarkerId('1'),
position: LatLng(25.00057631014206, 55.297173890099394),
draggable: false, onDragEnd: (updatedLatLng) {
// checkUp(updatedLatLng);
}),
//position: LatLng(latSelected, lngSelected),
];
Set circles = Set.from([
Circle(
circleId: CircleId('1'),
center: LatLng(25.00057631014206, 55.297173890099394),
radius: 700,
strokeWidth: 2,
// strokeColor: Color(0xFFB2DEFF),
fillColor: Color(0xFFE4F0F9).withOpacity(0.5))
]);
There is a method onTap(LatLng) on google maps it will give you lattitude and longitude coords from parameters.
You can check from there whether the current coords are inside the circle or not.
In my app, posts include a location. Currently, I am able to get coordinates (latitude and longitude), but for obvious reasons, I don't want to display users' coordinates publicly. My goal is to get the city, state, and country from those coordinates and then show a radius over that city on a map instead of a pin directly on the coordinates. Is this possible in Flutter and are there any examples of it?
After checking the source code of google_maps_flutter plugin, there is an example there of using the circles argument of GoogleMap Widget's constructor.
And on Circle's API documentation, you may create a Circle with an unique ID, then supply it to GoogleMap Widget's constructor
import 'package:google_maps_flutter/google_maps_flutter.dart';
// declare one Circle
Circle aCircle = Circle(
circleId: CircleId('unique_id_for_your_circle'), // required, unique
consumeTapEvents: false, // or true if you want it to intercept onTap events
fillColor: Colors.blue.withOpacity(0.5,), // to give it a color
center: const LatLng(0.0, 0.0), // where it is centered on your Map
radius = 100.0, // it's size
onTap: () {}, // if you want it to intercept if consumeTapEvents is true, or set to null if not used
);
// your Widget constructor
GoogleMap(
// ...other required arguments
circles: <Circle>{aCircle,}, // add your [Circle]s here, it's a Set, not a List
);
Objective:
To be able to show custom markers from dev only and disable google maps' default markers.
Description:
I am trying to put markers in GoogleMap from google_maps_flutter plugin but Google already has its own markers so it is getting in the way of the markers that I am trying to add. Is there any way to just show the map and add user-defined markers only? If not is it possible to minimize the number of markers shown by default map?
Just looked around and found some possible fix.
Seems like we can generate map style from this website:
Styling Wizard.
From there I toned down landmarks and then I was able to remove markers using this:
final String mapStyle =
await rootBundle.loadString('assets/map/map_style.txt');
//Set it on mapcontroller after map is created.
onMapCreated: (GoogleMapController controller) {
if (_controller.isCompleted) {
return;
}
controller.setMapStyle(mapStyle);
_controller.complete(controller);
},
// create a function to create custom marker
Future<BitmapDescriptor> createCustomMarkerBitmap() async {
Uint8List? data = await getBytesFromAsset("assets/icons/map_marker.png", 100);
return BitmapDescriptor.fromBytes(data!);
}
// then call the function to create a custom marker.
BitmapDescriptor? _marker = await createCustomMarkerBitmap();
final Marker marker = Marker(
markerId: _markerId,
position: _position,
icon: _marker, // use the marker
infoWindow: _infoWindow,
onTap: () {},
);
I want to code a custom marker which can load a profile pic of a user which is from API and the background should bind with the clip shape which is customized....
click here for view design
It looks like you are trying to use the google maps package, the marker in the package takes BitmapDescriptor, so basically you can load an image from asset. I did not try to add a margin to the marker icon, in my case I just edited the image.
final Uint8List markerIcon = await getBytesFromAsset('assets/images/map_pin.png', 600);
BitmapDescriptor customIcon = BitmapDescriptor.fromBytes(markerIcon);
marker.add(Marker(
markerId: MarkerId(currentLocation!.latitude.toString()),
position: currentLocation!,
draggable: true,
icon: customIcon,
onDragEnd: (LatLng latlng) {
currentLocation = latlng;
}));
I think you want ClipPath https://www.youtube.com/watch?v=oAUebVIb-7s and using some custom paths.
And then, position the map and your marker with a Stack widget.
I'm getting a straight line between my initial position and final position, which I don't want to show btw, along with the required route, like this:
How can I remove the straight line?
This is my code to draw the polyline:
setPolylines() async {
Polyline polyline = Polyline(
polylineId: PolylineId("poly"),
color: Colors.red[900],
points: polylineCoordinates,
width: 3,
);
_polylines.add(polyline);
}
Thanks in advance..
(Please do let me know if I need to add more data to this question!)