flutter google map marker for current position - flutter

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.

Related

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

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.

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

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

flutter how to get marker id when marker click?

I am using flutter. I want to get the clicked marker id when a marker is clicked on Google Maps. Or I would like to know if I clicked a marker or a map area. How can I do it?
First, you will create some variables,
one that will be the value of the markerId: MarkerId(markerValue1):
String markerValue1 = 'Your Marker Id';
one that will store the latest markerId value:
String latestMarkerValue;
Then you will add in your Marker widget theonTap: method:
onTap: (){
latestMarkerValue=markerValue1;
}
You will do this for every marker.
If you want to have all the clicked markers' ides then you will change the value of the latestMarkerValue
latestMarkerValue= latestMarkerValue==null?latestMarkerValue= 'markerValue1':latestMarkerValue='$latestMarkerValue $markerValuen'

How to remove a specific marker from google maps in flutter?

I am Vaibhav Pathak. I am working on a Flutter app in which I add markers in-app based on data change in firestore database and I want to remove the previous marker from the map using its marker id but I don't understand how to do it. I had watched many Youtube videos and blogs but I don't get to know this because of API changes in google maps flutter plugin. For your kind information, I want to tell that I am using the latest version of the google_maps flutter plugin.
My Code for Making Markers :
showLiveLocation(LatLng latLng) {
_markers.add(
Marker(
markerId: MarkerId(latLng.toString()),
position: latLng,
draggable: false,
infoWindow: InfoWindow(
title: "Live Order Location",
snippet: "Dear customer your order is live at this place."),
icon: liveLocation,
visible: true,
),
);
}
Thanks for everyone's help.
github : github#vkpdeveloper
You need to find that specific marker in your _markers list (e.g. by firstWhere()) and then remove it from the list of markers.
Edit:
Marker marker = _markers.firstWhere((marker) => marker.markerId.value == "myId",orElse: () => null);
setState(() {
_markers.remove(marker);
});
This will trigger a rebuild of your map where the marker is no longer included.
Inspired by Thomas, my solution was:
setState(() {
_markers.removeWhere((key, marker) => marker.markerId.value == "myMarkerId");
});