I am making a map view , in that on a latitude and longitude i want to show a pin, i am new to making such application in mapview.
if any one know it, please let me know.
thanks in advance
http://developer.apple.com/iphone/library/samplecode/MapCallouts/Introduction/Intro.html
this is the link get it and enjoy friend.
I will use this for show the pin in map.
func setupData() {
// 1. check if system can monitor regions
if CLLocationManager.isMonitoringAvailable(for: CLCircularRegion.self) {
// 2. region data
let title = ""
let allAnnotations = self.mapVW.annotations
self.mapVW.removeAnnotations(allAnnotations)
setZoom()
for item in arrPin
{
let dict = item as? NSDictionary
if let lat = dict?.value(forKey: "lat") as? String, let long = dict?.value(forKey: "lon") as? String
{
selectedPlaceAnnotation = MKPointAnnotation()
selectedPlaceAnnotation.coordinate = CLLocationCoordinate2DMake(Double(lat)!,Double(long)!)
mapVW.addAnnotation(selectedPlaceAnnotation)
arrAnnotation.add(selectedPlaceAnnotation)
}
}
}
}
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
guard !(annotation is MKUserLocation) else {
return nil
}
// Better to make this class property
let annotationIdentifier = "AnnotationIdentifier"
var annotationView = MKAnnotationView()
annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)
annotationView.frame = CGRect(x: annotationView.frame.origin.x, y: annotationView.frame.origin.y, width: 80, height: 200)
annotationView.annotation = annotation
annotationView.tag = index
index += 1
let imageViewPin = UIImageView(frame: CGRect(x: 0, y: 0, width: 30, height: 40))
imageViewPin.center = CGPoint(x: annotationView.center.x, y: annotationView.center.y - 11)
imageViewPin.image = UIImage(named: "green_pin")
annotationView.addSubview(imageViewPin)
return annotationView
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.