Hi everybody,
I am developing a system for IOS and in the future it to Android too,so I'm using Xamarin.Forms.
On my Map App I need add pins on map, the pin will be put in a specific local on map.
What best Idea for development this?
Remember, I already have added pins on the map, but all comes from a database with location already determined. At this new pin who will choose the location is the User.
I would not recommend using single tap to add pins to the map, that may interfere with the selection of a pin.
For example, you can use LongPress
instead. To do that add a UILongPressGestureRecognizer
to the MKMapView
in your MapRenderer
.
protected override void OnElementChanged(ElementChangedEventArgs<View> e) { base.OnElementChanged(e); if (e.OldElement != null) return; var map = this.Control as MKMapView; if(map == null) return; map.AddGestureRecognizer(new UILongPressGestureRecognizer(MapLongPress)); } private void MapLongPress(UILongPressGestureRecognizer recognizer) { if (recognizer.State != UIGestureRecognizerState.Began) return; var map = this.Control as MKMapView; if(map == null) return; var pixelLocation = recognizer.LocationInView(map); var geoCoordinate = map.ConvertPoint(pixelLocation, map); // Add new Annotation(pin) with the coordinate }
Answers
Pins are added via Latitude/Longitude coordinates and the documentation is found here.
If the user needs to choose a location, you're probably going to have to write a custom renderer that exposes the touch event. There will be a callback with the coordinates that you can then set to your ViewModel if you need to store it later.
@TioWidow
I would not recommend using single tap to add pins to the map, that may interfere with the selection of a pin.
For example, you can use
LongPress
instead. To do that add aUILongPressGestureRecognizer
to theMKMapView
in yourMapRenderer
.Thanks for listening
I will try to use this with the custom renderer because I am using a object Map ("xamarin.forms.maps") in a Page.
Anyway I believe that your help will be very useful.
I am working with maps in xamarin iOS and I need to detect a tap and add a pin in the location tapped.

For exemple, the image below I have sectors on a map and if the user touches one of the sectors I execute a method that verify if touch is inside or outside of the polygon, that isn't the problem! but after in case I verified that it is inside, how can I add the pin at the sector?