How to show message in flutter after on Tap in google map "You are out of Zone" - flutter

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.

Related

How to show a map with a radius aon a city from coordinates - Flutter

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
);

MapBox-gl Flutter - show my current location on map

I added My Location button + on click event like this:
FloatingActionButton(
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(12.0))),
child: const Icon(Icons.gps_fixed_sharp, size: 25),
onPressed: () async {
try {
var position = await _determinePosition();
mapController?.animateCamera(CameraUpdate.newLatLngZoom(LatLng(position.latitude, position.longitude), 17));
} catch (e) {
FToast.toast(context, msg: e.toString());
}
},
)
So, after location determined, camera is animated to my location. It works, but I'm getting problem with blue point showing my current location on map. It's enabled by default with myLocationEnabled: true, in MapboxMap constructor. It's visible only when app is started with location permissions allowed.
After user taps "My Location" button, app displays prompt to allow location permissions, then determines location and moves camera. However, in this case, still MapBox does not show my location point - I need to restart app to get it visible.
How to tell Mapbox that location permissions have been granted to show my location point on map? I can't find any method inside map controller to do so.

How to get LatLng position by clicking the maps in flutter

I am using google_maps_flutter to show the maps of user location, I come up with an idea where user can click anything in maps and show the the coordinates they clicked. What I mean with the coordinates here is Lat and Lng position that the click from the maps. Is that possible to do that ? and are there some articles as guide for me to do that ?
use onTap callback of GoogleMap widget like below to get coordinates from map where use clicks.
GoogleMap(
onTap: (LatLng latLng) {
final lat = latLng.latitude;
final long = latLng.longitude;
},
);

How to draw polygon in Google map Flutter dynamically

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

flutter google map marker for current position

How could I have goolge map's style marker for current location , it can even show the direction of current position ?
this is my code, the marker style of my code is just a pin, i want
to have google map's marker style even to show the direction of current position .
_markerSet.add(
Marker(
markerId: MarkerId('current_Postion'),
infoWindow: InfoWindow(title: 'Current Position'),
position: _userCurrentPositionLatLng,
icon: BitmapDescriptor.defaultMarkerWithHue(
BitmapDescriptor.hueGreen,
),
),
This is how my marker looks like
enter image description here
This is the google marker which i want to have
enter image description here
Any hints for suggestions?
Edit:
Set myLocationEnabled: true, on the GoogleMap widget. It will automatically take care of that.
This works for a custom marker:
You cannot directly get the location from Google Map.
You can use this location package to get the users location (latitude and longitude) and then add the marker accordingly to the map.