How do I drop a pin with MapKit?

前端 未结 4 1563
一向
一向 2020-12-24 02:56

I would like to allow the user of my app to pick a location in the map. The native map has a \"drop pin\" feature where you can locate something by dropping a pin. How can I

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-24 03:49

    you can get touched location by ,jcesarmobile answer on get tapped coordinates with iphone mapkit and you can drop pin any where as bellow

    // Define pin location
    CLLocationCoordinate2D pinlocation;
    pinlocation.latitude = 51.3883454 ;//set latitude of selected coordinate ;
    pinlocation.longitude = 1.4368011 ;//set longitude of selected coordinate;
    
    // Create Annotation point 
    MKPointAnnotation *Pin = [[MKPointAnnotation alloc]init];
    Pin.coordinate = pinlocation;
    Pin.title = @"Annotation Title";
    Pin.subtitle = @"Annotation Subtitle";
    
    // add annotation to mapview
    [mapView addAnnotation:Pin];
    

提交回复
热议问题