Xamarin.iOS 上的自定义 Google 地图标记信息视图 [英] Custom Google Maps marker info view on Xamarin.iOS

查看:33
本文介绍了Xamarin.iOS 上的自定义 Google 地图标记信息视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IMapViewDelegate 显然不是来自 objC 的 MapViewDelegate 的完整 C# 实现.这会禁止访问 markerInfoContents 委托方法.
我想做这样的事情,允许我自定义 contentView 布局和点击动作

来自:

_mapView.InfoTapped += (object sender, GMSMarkerEventEventArgs e) =>{Console.WriteLine ("标记信息已点击:"+e+"::"+sender);UIAlertView 警报 = 新 UIAlertView () {标题 =警报",消息 = sampleLongandLat};alert.AddButton("OK");警报.显示();};

上面的代码片段可用于检测标记信息窗口上的点击

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

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

解决方案

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

_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

这篇关于Xamarin.iOS 上的自定义 Google 地图标记信息视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆