2

The IMapViewDelegate apparently isn't a complete C# implementation of MapViewDelegate from objC. That inhibits the access to markerInfoContents delegate method.
I'd like to do something like this allowing me to custom the contentView layout and the tap action from raywenderlich.com

got from: http://www.raywenderlich.com/81103/introduction-google-maps-ios-sdk-swift

vbrittes
  • 200
  • 1
  • 14
  • In Objective-C, you need to override the `(UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker` method, I think you need to override similar method in xamarin. In order to use Google Maps for iOS, you need to download the component: https://components.xamarin.com/view/googlemapsios . For tap event, you can refer to this post: http://forums.xamarin.com/discussion/2612/google-maps-sdk-how-to-capture-marker-tap – ztan Feb 13 '15 at 21:33
  • Most of the delegate methods are available. Although there are some variations like the tap event that instead of implementing a delegate method, is set through an anon method. I'm looking for a similar solution to setup the marker info window as it would if the markerInfoWindow method were implemented. – vbrittes Feb 14 '15 at 00:37
  • Anyone? We have the some problem. We have tried this (but not got it to work) http://stackoverflow.com/questions/14123243/google-maps-android-api-v2-interactive-infowindow-like-in-original-android-go – Johan Karlsson Mar 06 '15 at 09:31
  • Did you get the answer, I also struggling with this and I am created my map using xamarin forms google map – Aswathy K R Sep 15 '18 at 10:36

1 Answers1

4

I think i can explan its from scratch to add a Custom MarkerInfo Window on the Tap of a Marker. Iam using Xamarin.Google.iOS.Maps package from Official Nuget Library for adding Google Map on my Xamarin MVVM Cross Touch Project.

private void SetupMap()
            {
                if (_mapView != null)
                    _mapView.RemoveFromSuperview ();

            //Init Map wiht Camera
            var camera = new CameraPosition(new CLLocationCoordinate2D(36.069082, -94.155976), 15, 30, 0);
            _mapView = MapView.FromCamera(RectangleF.Empty, camera);
            _mapView.MyLocationEnabled = true;
            //Add button to zoom to location
            _mapView.Settings.MyLocationButton = true;
            _mapView.MyLocationEnabled = true;
            _mapView.Settings.SetAllGesturesEnabled(true);

            var xamMarker = new Marker () {
                Title = "Sample",
                Snippet = "Sample Location",
                Position = new CLLocationCoordinate2D (36.069082, -94.155976),
                Map = _mapView
            };
            var xamMarker1 = new Marker () {
                Title = "Sample1",
                Snippet = "Sample Location2",
                Position = new CLLocationCoordinate2D (35.069082, -94.155976),
                Map = _mapView
            };

            _mapView.TappedMarker = (map, marker) => {
                Console.WriteLine("Marker tapped:"+ map +"::"+marker);

                _mapView.MarkerInfoWindow = new GMSInfoFor(markerInfoWindow);
                return false;
            };
            _mapView.Frame = this.contentViewOutlet.Bounds;
            this.contentViewOutlet.AddSubview (_mapView);

            _mapView.InfoTapped += (object sender, GMSMarkerEventEventArgs e) => {
                Console.WriteLine ("Marker Info tapped:"+e+"::"+sender);

                UIAlertView alert = new UIAlertView () { 
                    Title = "Alert", Message = sampleLongandLat
                };
                alert.AddButton("OK");
                alert.Show ();

            };
        }

you can call this SetupMap() method from where ever you want. for example in ViewDidLoad or from any where you have to add the google map.

On click or Tap of the marker we are creating a custom marker window

_mapView.TappedMarker = (map, marker) => {
                Console.WriteLine("Marker tapped:"+ map +"::"+marker);

                _mapView.MarkerInfoWindow = new GMSInfoFor(markerInfoWindow);
                return false;
            };

the above code is included in the SetupMap method.

mapView.MarkerInfoWindow = new GMSInfoFor(markerInfoWindow); these above line of code will allow us to load a custom Marker Window instead of the default one

    UIView markerInfoWindow(UIView view, Marker marker)
            {
// use this method to return the custom view u have already created to load as a subview in Google Map as Custom Marker Info Windo
                UIView v;
                v = MarkerInfoView.Create(marker);
                sampleLongandLat = MarkerInfoView.markerInfoString;
                sampleLongandLat = MarkerInfoView.locationIDString;
                return v;
            }

for adding an custom UIView you can follow the example provided in the xamarin web site loading an xib or UIView in another ViewController as a sub viewenter image description here

_mapView.InfoTapped += (object sender, GMSMarkerEventEventArgs e) => {
                Console.WriteLine ("Marker Info tapped:"+e+"::"+sender);

                UIAlertView alert = new UIAlertView () { 
                    Title = "Alert", Message = sampleLongandLat
                };
                alert.AddButton("OK");
                alert.Show ();

            };

the above code snippet you can use for detecting tap on the Marker Info Window

SARATH SASI
  • 1,395
  • 1
  • 15
  • 39