Xamarin.Forms.GoogleMaps
Xamarin.Forms.GoogleMaps copied to clipboard
Option to Disable Info Window on Pin Selection
SUMMARY
I have a project that deals with selected pins on a specific UI the pops in the screen. I need a away to disable the InfoWindow to be presented automatically when the pin is selected.
DETAILS
The use case is when you need to track a Pin selection but doesn't want it to display the Info Window attached to the Pin. I have attached a screenshot with an example of this use case:
Notice that my UI provides a panel below the screen where I can get information for the selected Pin and also do some interaction, so the InfoWindow doesn't provide any valuable addition to this specific use case, and also occupy unwanted space on the screen.
Disabling the InfoWindow pin should be implemented like an flag property that could be set directly in XAML.
PLATFORMS
- [x] Android
- [x] iOS
- [ ] UWP
You can handling pin behavior when clicked.
https://github.com/amay077/Xamarin.Forms.GoogleMaps/blob/e07feeee9bf49606ed0a532627b1c8f3115a467e/XFGoogleMapSample/XFGoogleMapSample/PinsPage.xaml.cs#L166-L179
Pin selection doesn't work automatically
means do not open InfoWindow automatically.
But be careful if you hope disable InfoWindow, you can not Map.SelectedPin = xxx
always.
This is a way of doing this, but I need to keep the SelectedPin
property. I've implemented this as a platform effect. Please tell me if you want to add it as option with a Pull Request.
I found Google Maps SDK's behavior.
https://developers.google.com/maps/documentation/ios-sdk/marker#add_an_info_window
Clicking the marker does not display an info window if both the title and snippet properties are blank or nil.
So I have a plan to support "Disable InfoWindow" .
- Add
UiSettings.InfoWindowEnabled as bool
property - In Android/iOS side
PinLogic
, IfUiSettings.InfoWindowEnabled
is false then skip update marker'sTitle
andSnippet
https://github.com/amay077/Xamarin.Forms.GoogleMaps/blob/ba855acdd86c35d6478d701d696f61cea30c3695/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.Android/Logics/PinLogic.cs#L78-L90
https://github.com/amay077/Xamarin.Forms.GoogleMaps/blob/ba855acdd86c35d6478d701d696f61cea30c3695/Xamarin.Forms.GoogleMaps/Xamarin.Forms.GoogleMaps.iOS/Logics/PinLogic.cs#L74-L84
Could you create Pull request, @ravero ?
Could you create Pull request, @ravero ?
Of course! I'll prepare this.
I would also know if there is a way to disable the info window simply.
I would also know if there is a way to disable the info window simply.
I just put the pin label to null and it doesn't show the InfoWindow
I tried null and I get an error: System.ArgumentException: 'Pin must have a Label to be added to a map'
However, using String.Empty works - no error and no info window, thank you!
Pin pin = new Pin
{
Icon = BitmapDescriptorFactory.DefaultMarker(Color.Red),
Position = position,
Tag = "whatever",
Label = string.Empty
};
Don't you have an "Input string was not in a correct format." when you select a pin, unselect and select it again? This is what I get with string.empty
@amay077 @ravero Any update about the PR? I'm open to help if needed
In order to hide InfoWindow you need to create your own implementation of MapDelegate and override MarkerInfoWindow method, like that ->
public override UIView MarkerInfoWindow(MapView mapView, Marker marker)
{
return new UIView();// base.MarkerInfoWindow(mapView, marker);
}
Btw. returning null doesn't work ;)
You can handling pin behavior when clicked.
https://github.com/amay077/Xamarin.Forms.GoogleMaps/blob/e07feeee9bf49606ed0a532627b1c8f3115a467e/XFGoogleMapSample/XFGoogleMapSample/PinsPage.xaml.cs#L166-L179
Pin selection doesn't work automatically
means do not open InfoWindow automatically. But be careful if you hope disable InfoWindow, you can notMap.SelectedPin = xxx
always.
Thank you! This does exactly what I have been wanting do to for a long time. Though a formal option to disable the info window would make it more discoverable (and preserve pin selection).