I have latitude and long values and I need to be able to drop a pin at this location.
Can anybody provide some advice on how to go about this?
I have latitude and long values and I need to be able to drop a pin at this location.
Can anybody provide some advice on how to go about this?
You should:
1. add the MapKit framework to your project. 2. create a class which implements the MKAnnotation protocol.
Sample:
Annotation.h
Annotation.m
2. create an instance of this class and set the lat/lon property
3. add the instance to the MKMapView object with this method:
4. You should set the delegate of the map and implement the following method:
Find the below very simple solution to drop the pin at given location define by CLLocationCoordinate2D
Drop Pin on MKMapView
Edited:
This assumes that you have ARC enabled and that you have included the MapKit framework.
First create a class that implements the MKAnnotation protocol. We'll call it MapPinAnnotation.
MapPinAnnotation.h
MapPinAnnotation.m
Then add the annotation to the map using the following:
The containing class will have to implement the MKMapViewDelegate protocol. In particular you will have to define the following function to draw the pin:
In this example the MKAnnotation title and subtitle member variables are not used, but they can be displayed in the delegate function.
Swift Version