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);
};
سؤال
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.
المحلول
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);
};
نصائح أخرى
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;
}