how to handle click event in Xamarin google map component for ios

随声附和 提交于 2019-12-22 10:49:09

问题


I am using xamarin googel map component to develop google map application in iOS. When user touches the map I want to get the location of the map that user touches. any idea.

thanks in advance.


回答1:


MapView has a tapped event, as well as multiple Touches* events

mapView.Tapped += delegate(object sender, GMSCoordEventArgs e) {
  Console.WriteLine("tapped at " + e.Coordinate.Latitude + "," + e.Coordinate.Longitude);
};



回答2:


GoogleMap : Marker click event with and without ClusterManager

For Xamarin.iOS , Google Map will use TappedMarker event. It might be used in three different ways.


First way of implementation:


You can directly use MapView Delegate event didTapMarker . It will work along with GMUClusterManager such as

    [Export("mapView:didTapMarker:")]
    public bool TappedMarker(MapView mapView, Marker marker)
    {
        var id = marker.Title;
        Console.WriteLine(id);

        return true;
    }

Second way of implementation:


For your GoogleMap, we can directly use TappedMarker method

    this.GMapView.TappedMarker = (map, marker) =>
    {
        var id = marker.Title;
        Console.WriteLine(id);

        return true;
    }

Third way of implementation:


For your GoogleMap , you can use your own custom method for TappedMarker event.

    this.GMapView.TappedMarker = markerClicked;

Definition of markerClicked is here

    bool markerClicked(MapView map, Marker marker)
    {
        var id = marker.Title;
        Console.WriteLine(id);

        return true;
    }


来源:https://stackoverflow.com/questions/22838462/how-to-handle-click-event-in-xamarin-google-map-component-for-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!