Google Map Marker Click

hi, i have implement google map in my application and also i have inserted markers according to some lattitude and longitude. and now i want i implement marker click event(onmarkerclick) in my application please help any one.
how can i implement this ?.

My code is for implement marker
_map.AddMarker(new MarkerOptions().SetPosition(getlatlong).SetTitle(CompanyName).SetSnippet("Sold: " + Sold + "Offered: " + Offered));

Posts

  • CheesebaronCheesebaron DKInsider, University mod

    What does this have to do with Visual Studio?

  • actually i want to implement, google maps marker info window click using visual studio in mono android....
    please reply as soon as possible.
    thanks in advance.....

  • Hi, GoogleMap class has MarkerClick event.

  • Emixam23Emixam23 USMember ✭✭✭

    Yeah but if you work with a PCL project so you wil create a CustomPin object or what ever. Then in the MapRenderer, you need to know which custom pins has been clicked, but how? In both Android & UWP I have a Dictionnary<MapIcon/Marker, CustomPin> so then, I search from either the MapIcon or the Marker. However, it only works for UWP, on Android the dictionnary cannot find the related CustomPin..

  • Emixam23Emixam23 USMember ✭✭✭
    edited December 2016

    I found something !

    This is my dictionnary:

        /// <summary>
        /// Link between custom pins and their renderers.
        /// </summary>
        private Dictionary<Marker, CustomPin> MarkerOptionsPinLinkDictionary;
    

    Then I add this :

        /// <summary>
        /// This function only takes place on Android plateform.
        /// This function is the native callback called when the map is loaded.
        /// </summary>
        /// <param name="googleMap">The native map instance.</param>
        public void OnMapReady(GoogleMap googleMap)
        {
            //....
            nativeMap.MarkerClick += OnPinClicked;
            UpdatePins();
        }
    

    So I got handle the click like that

        /// <summary>
        /// Function called when a pin get clicked.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The element.</param>
        private void OnPinClicked(object sender, MarkerClickEventArgs e)
        {
            var item = this.MarkerOptionsPinLinkDictionary.FirstOrDefault(i => i.Value.Id.Equals(e.Marker.Title));
            CustomPin pin = item.Value;
        }
    
  • jimbeijimbei USMember ✭✭

    @Emixam23 said:
    I found something !

    This is my dictionnary:

        /// <summary>
        /// Link between custom pins and their renderers.
        /// </summary>
        private Dictionary<Marker, CustomPin> MarkerOptionsPinLinkDictionary;
    

    Then I add this :

        /// <summary>
        /// This function only takes place on Android plateform.
        /// This function is the native callback called when the map is loaded.
        /// </summary>
        /// <param name="googleMap">The native map instance.</param>
        public void OnMapReady(GoogleMap googleMap)
        {
            //....
            nativeMap.MarkerClick += OnPinClicked;
            UpdatePins();
        }
    

    So I got handle the click like that

        /// <summary>
        /// Function called when a pin get clicked.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The element.</param>
        private void OnPinClicked(object sender, MarkerClickEventArgs e)
        {
            var item = this.MarkerOptionsPinLinkDictionary.FirstOrDefault(i => i.Value.Id.Equals(e.Marker.Title));
            CustomPin pin = item.Value;
        }
    

    @Emixam23 can i see your source code for custom pin properties?

  • Emixam23Emixam23 USMember ✭✭✭

    I now have a full implementation :)

    Just over here => https://github.com/Emixam23/XamarinByEmixam23/tree/master/Detailed Part/Controls/Map

    However, I haven't updated it since a while

  • jimbeijimbei USMember ✭✭

    @Emixam23 wow thank you very much i'll check that.

  • jimbeijimbei USMember ✭✭

    @Emixam23 hi i checked your project and saw it's a xamarin.forms project. Can i implement it on xamarin.android?

  • Emixam23Emixam23 USMember ✭✭✭
    edited November 7

    Check this file in the Xamarin.Droid part, because even if it's a Xamarin.Forms project, it can't be implemented without a renderer

    https://github.com/Emixam23/XamarinByEmixam23/blob/master/Detailed Part/Controls/Map/MapPinsProject/MapPinsProject/MapPinsProject.Droid/CustomRenderer/CustomMapRenderer.cs

    Also, this file is the source code you were asking above :)

  • jimbeijimbei USMember ✭✭

    @Emixam23 thanks you very much! big help for me.

  • Emixam23Emixam23 USMember ✭✭✭
    edited November 7

    You're welcome buddy, good luck !

Sign In or Register to comment.