[英]how to show pin on the map for iphone
我正在做一個地圖視圖,在緯度和經度上我想顯示一個圖釘,我是新來在mapview中進行這種應用的人。
如果有人知道,請告訴我。
提前致謝
我將用它在地圖上顯示圖釘。
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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.