0

How to make button clickable inside infowindow of google map using xamarin android, I have found few answers but they are for android studio, i have uploaded an image of layout to understand the question, click here 1

    private GoogleMap mMap;
    private Marker marker;
    private int bottomOffsetPixels;
    private View infoWindow;
    private Button callButton;

      public void setMarker(Marker marker)
    {
        this.marker = this.marker;
    }

    private void SetupMap()
    {
        if (mMap == null)
        {
            try
            {
                SetContentView(Resource.Layout.markmap);
                var mapFragment = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map);
                mapFragment.GetMapAsync(this);
            }
            catch (Exception ex) { }
        }
    }
      public void OnMapReady(GoogleMap googleMap)
    {
        this.mMap = googleMap;
        // googleMap.MapType = GoogleMap.MapTypeHybrid;

        mMap.UiSettings.ZoomControlsEnabled = true;

        LatLng latlng = new LatLng(Convert.ToDouble(37.35), Convert.ToDouble(-122.2));
        CameraUpdate camera = CameraUpdateFactory.NewLatLngZoom(latlng, 10);
        mMap.AnimateCamera(camera);

        string title1 = "jhon";

        mMap.AddMarker(new MarkerOptions()
      // .SetTitle("Prague")
       .SetIcon(GetCustomBitmapDescriptor(title1))
       .SetPosition(new LatLng(37.35,-122.2)));
       mMap.SetInfoWindowAdapter(this);
       }
          public View GetInfoWindow(Marker marker)
    {
        View view = LayoutInflater.Inflate(Resource.Layout.infoWindowMarker, null, false);
        return view;
    }

after creating map

     public View GetInfoContents(Marker marker)
    {
        var inflater = Android.App.Application.Context.GetSystemService(Context.LayoutInflaterService) as Android.Views.LayoutInflater;

        if (inflater != null)
        {
             callButton = infoWindow.FindViewById<Button>(Resource.Id.call);
            this.marker = marker;
            return infoWindow;
        }
        return null;
    }


    private void InfoWindowTouch(MotionEvent e)
    {

        switch (e.ActionMasked)
        {
            case MotionEventActions.Up:

        int buttonLeft = ((Android.Views.View)(callButton.Parent)).Left;
        int buttonTop = ((Android.Views.View)(callButton.Parent)).Top;
        Rect buttonRect = new Rect(buttonLeft, buttonTop, buttonLeft + callButton.Width, buttonTop + callButton.Height);
        if (buttonRect.Contains((int)e.GetX(), (int)e.GetY()))
        {
            int x = 0;
        }
        break;
        default: 
        break;
    }
}
    public override bool DispatchTouchEvent(MotionEvent e)
    {
        if ((marker != null) && marker.IsInfoWindowShown)
        {
            Android.Graphics.Point point = mMap.Projection.ToScreenLocation(marker.Position);
            MotionEvent copyEv = MotionEvent.Obtain(e);
            copyEv.OffsetLocation(
            -point.X + (infoWindow.Width / 2),
            -point.Y + infoWindow.Height + ConvertDpToPx(59));
            InfoWindowTouch(copyEv);
        }
        return base.DispatchTouchEvent(e);
    }
    public int ConvertDpToPx(float dp)
    {

        return (int)(dp * Resources.DisplayMetrics.Density + 0.5f);
    }

Tried to convert java android code to xamarin android, the code is running but still button aren't clickable.

Sj Raza
  • 103
  • 1
  • 6
  • Possible duplicate of [Google Maps Android API v2 - Interactive InfoWindow (like in original android google maps)](https://stackoverflow.com/questions/14123243/google-maps-android-api-v2-interactive-infowindow-like-in-original-android-go) – FreakyAli Feb 08 '19 at 09:35
  • Above link is for android studio and the other answers are for xamarin.form but i am struggling with xamarin.android. the code above is also fail try of converting code from android studio to xamarin.android. – Sj Raza Feb 09 '19 at 14:43
  • What part of this code are you struggling to convert? – FreakyAli Feb 11 '19 at 20:17
  • I have converted it all but still the button on info window isn't worikng, and there is no error message. – Sj Raza Feb 12 '19 at 02:26
  • Add the converted code and we can have a look – FreakyAli Feb 12 '19 at 02:37
  • @G.hakim The above code it converted from this https://stackoverflow.com/questions/14123243/google-maps-android-api-v2-interactive-infowindow-like-in-original-android-go – Sj Raza Feb 12 '19 at 06:14

0 Answers0