Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Xamarin Forms Map is not working in android

$
0
0

Hi Team , i am facing a issues after updating Xamarin Forms to latest .
The issues is in android side i am not able to display the custom pins the break pointer is not triggering "e.PropertyName.Equals("VisibleRegion") && !isDrawn" condition in customrenderer . map is displaying but not the pins. map Google map is not initialising.

GoogleMap map;
List customPins;
bool isDrawn;

    protected override void OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs<Map> e)
    {
        base.OnElementChanged (e);

        if (e.OldElement != null) {
            map.InfoWindowClick -= OnInfoWindowClick;
        }

        if (e.NewElement != null) {
            var formsMap = (CustomMap)e.NewElement;
            customPins = formsMap.CustomPins;
            ((MapView)Control).GetMapAsync (this);
        }
    }

    public void OnMapReady (GoogleMap googleMap)
    {
        map = googleMap;
        map.InfoWindowClick += OnInfoWindowClick;
        map.SetInfoWindowAdapter (this);
        isDrawn = false;
    }

    protected override void OnElementPropertyChanged (object sender, PropertyChangedEventArgs e)
    {
        base.OnElementPropertyChanged (sender, e);
        if (e.PropertyName.Equals("VisibleRegion") && !isDrawn)
        {
            map.Clear();

            foreach (var pin in customPins)
            {
                var marker = new MarkerOptions();
                marker.SetPosition(new LatLng(pin.Pin.Position.Latitude, pin.Pin.Position.Longitude));
                marker.SetTitle(pin.Pin.Label);
                marker.SetSnippet(pin.Pin.Address);


                //if (pin.Pin.Type == PinType.Place)
                //{
                //marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.ic_branches));
                //}
                if (pin.Type.ToString() == pin.branchId)
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.ic_branches));
                }
                else if (pin.Type.ToString() == pin.kioskId)
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.ic_kiosks));
                }
                else if (pin.Type.ToString() == pin.partnerId)
                {
                    marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.ic_partner));
                }


                map.AddMarker(marker);


            }
            isDrawn = true;
        }
    }

Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>