amay077 / Xamarin.Forms.GoogleMaps

Map library for Xamarin.Forms using Google maps API
https://www.nuget.org/packages/Xamarin.Forms.GoogleMaps/
MIT License
546 stars 346 forks source link

Option to Disable Info Window on Pin Selection #613

Open ravero opened 5 years ago

ravero commented 5 years ago

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:

Simulator Screen Shot - iPhone 8 - 2019-03-19 at 12 04 39

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

amay077 commented 5 years ago

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.

ravero commented 5 years ago

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.

amay077 commented 5 years ago

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" .

  1. Add UiSettings.InfoWindowEnabled as bool property
  2. In Android/iOS side PinLogic, If UiSettings.InfoWindowEnabled is false then skip update marker's Title and Snippet

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 ?

ravero commented 5 years ago

Could you create Pull request, @ravero ?

Of course! I'll prepare this.

alexpdaniel commented 5 years ago

I would also know if there is a way to disable the info window simply.

Kingamattack commented 5 years ago

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

alexpdaniel commented 5 years ago

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
                };
Kingamattack commented 5 years ago

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

Kingamattack commented 5 years ago

@amay077 @ravero Any update about the PR? I'm open to help if needed

mariuszdybala commented 4 years ago

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

AlexKven commented 4 years ago

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.

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