- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 map 上有 20 个图钉,点击后每个图钉都会显示带有 field 名称的注释,并且右侧有一个标注按钮。我已使用 segue 成功将此按钮链接到单个页面。问题是所有位置都链接到同一页面。我想要 20 个单独的页面,每个页面都链接到一个特定的 pin。我在网上找到的几乎所有示例都希望生成一个包含传入信息的页面。这是我的代码。
import UIKit
import MapKit
import CoreLocation
class MapContollerViewController: UIViewController, CLLocationManagerDelegate {
@IBOutlet weak var mapView: MKMapView!
// NEED TO SET THIS INT SOMEWHERE DEPENDING ON WHICH LOCATION IS SELECTED
var venueNo: Int = 2
// MARK: - CLLocationManager
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
checkLocationAuthorizationStatus()
}
let locationManager = CLLocationManager()
func checkLocationAuthorizationStatus() {
if CLLocationManager.authorizationStatus() == .authorizedAlways {
mapView.showsUserLocation = true
} else {
locationManager.requestAlwaysAuthorization()
}
}
let regionRadius: CLLocationDistance = 800
func centerMapOnLocation(location: CLLocation) {
let coordinateRegion = MKCoordinateRegionMakeWithDistance(location.coordinate,
regionRadius, regionRadius)
mapView.setRegion(coordinateRegion, animated: true)
}
override func viewDidLoad() {
let classInstance = MapContollerViewController() //swift allocates memory and creates an instance
classInstance.venueNo = 2
super.viewDidLoad()
mapView.delegate = self
let initialLocation = CLLocation(latitude: 56.457539, longitude: -2.9821680000000015)
//UNION
let artwork = Artwork(title: "The Union",
locationName: "Airlie Place",
discipline: "Venue",
coordinate: CLLocationCoordinate2D(latitude: 56.457539, longitude: -2.9821680000000015),
venueNo:1)
//changing value here but in wrong place
venueNo = 1
mapView.addAnnotation(artwork)
// TINSMITH
let artwork2 = Artwork(title: "The Tin Smith",
locationName: "11-13 Old Hawkhill",
discipline: "Venue",
coordinate: CLLocationCoordinate2D(latitude: 56.4594785, longitude: -2.980198400000063),
venueNo:2)
mapView.addAnnotation(artwork2)
// Grafters
let artwork3 = Artwork(title: "Grafters",
locationName: "Union Street",
discipline: "Venue",
coordinate: CLLocationCoordinate2D(latitude: 56.4588498, longitude: -2.9709077999999636),
venueNo:3)
mapView.addAnnotation(artwork3)
// The Bird & Bear
let artwork4 = Artwork(title: "The Bird & Bear",
locationName: "2 Whitehall Cres",
discipline: "Venue",
coordinate: CLLocationCoordinate2D(latitude: 56.4592973, longitude: -2.968744700000002),
venueNo:4)
mapView.addAnnotation(artwork4)
// The Salty Dog
let artwork5 = Artwork(title: "The Salty Dog",
locationName: "9 Crichton St",
discipline: "Venue",
coordinate: CLLocationCoordinate2D(latitude: 56.459916, longitude: -2.9701755999999477),
venueNo:5)
mapView.addAnnotation(artwork5)
// Jam Jar
let artwork6 = Artwork(title: "Jam Jar",
locationName: "2b Whitehall Cres",
discipline: "Venue",
coordinate: CLLocationCoordinate2D(latitude: 56.45916279999999, longitude: -2.9688820999999734),
venueNo:6)
mapView.addAnnotation(artwork6)
// Church
let artwork7 = Artwork(title: "Church",
locationName: "15 Ward Rd",
discipline: "Venue",
coordinate: CLLocationCoordinate2D(latitude: 56.4617273, longitude: -2.9758415000000014),
venueNo:7)
mapView.addAnnotation(artwork7)
// No'1s
let artwork8 = Artwork(title: "No'1s",
locationName: "1 Ward Rd",
discipline: "Venue",
coordinate: CLLocationCoordinate2D(latitude: 56.4618699, longitude: -2.9745715000000246),
venueNo:8)
mapView.addAnnotation(artwork8)
// Medina
let artwork9 = Artwork(title: "Medina",
locationName: "113 Nethergate",
discipline: "Venue",
coordinate: CLLocationCoordinate2D(latitude: 56.4576889, longitude: -2.9751609),
venueNo:9)
mapView.addAnnotation(artwork9)
// Westport
let artwork10 = Artwork(title: "Westport Bar",
locationName: "N Lindsay St",
discipline: "Venue",
coordinate: CLLocationCoordinate2D(latitude: 56.4606814, longitude: -2.975895000000037),
venueNo:10)
mapView.addAnnotation(artwork10)
// D'Arcy thompson
let artwork11 = Artwork(title: "D'Arcy Thompson",
locationName: "Old Hawkhill",
discipline: "Venue",
coordinate: CLLocationCoordinate2D(latitude: 56.4594204, longitude: -2.9805648999999903),
venueNo:11)
mapView.addAnnotation(artwork11)
// Tonic
let artwork12 = Artwork(title: "Tonic",
locationName: "141 Nethergate",
discipline: "Venue",
coordinate: CLLocationCoordinate2D(latitude: 56.4572926, longitude: -2.9762908000000152),
venueNo:12)
mapView.addAnnotation(artwork12)
// The Beer Kitchen
let artwork13 = Artwork(title: "The Beer Kitchen",
locationName: "10 S Tay St",
discipline: "Venue",
coordinate: CLLocationCoordinate2D(latitude: 56.457705, longitude: -2.975928000000067),
venueNo:13)
mapView.addAnnotation(artwork13)
// Braes
let artwork14 = Artwork(title: "Braes",
locationName: "Perth Rd",
discipline: "Venue",
coordinate: CLLocationCoordinate2D(latitude: 56.45660329999999, longitude: -2.9789081000000124),
venueNo:14)
mapView.addAnnotation(artwork14)
// The Nether Inn
let artwork15 = Artwork(title: "Nether Inn",
locationName: "134 Nethergate",
discipline: "Venue",
coordinate: CLLocationCoordinate2D(latitude: 56.4580593, longitude: -2.974011799999971),
venueNo:15)
mapView.addAnnotation(artwork15)
// The Underground
let artwork16 = Artwork(title: "Underground",
locationName: "25 S Tay St",
discipline: "Venue",
coordinate: CLLocationCoordinate2D(latitude: 56.4583296, longitude: -2.975921200000016),
venueNo:16)
mapView.addAnnotation(artwork16)
// George Orwell
let artwork17 = Artwork(title: "George Orwell",
locationName: "168 Perth Rd",
discipline: "Venue",
coordinate: CLLocationCoordinate2D(latitude: 56.4561959, longitude: -2.986077499999965),
venueNo:17)
mapView.addAnnotation(artwork17)
// Balcony Bar
let artwork18 = Artwork(title: "Balcony Bar",
locationName: "5 Ward Rd",
discipline: "Venue",
coordinate: CLLocationCoordinate2D(latitude: 56.4618648, longitude: -2.9748177999999825),
venueNo:18)
mapView.addAnnotation(artwork18)
// McDaniels
let artwork19 = Artwork(title: "McDaniels",
locationName: "34-36 Whitehall Cres",
discipline: "Venue",
coordinate: CLLocationCoordinate2D(latitude: 56.45888000000001, longitude: -2.969510000000014),
venueNo:19)
mapView.addAnnotation(artwork19)
// TheWest House
let artwork20 = Artwork(title: "The West House",
locationName: "2 West Port",
discipline: "Venue",
coordinate: CLLocationCoordinate2D(latitude: 56.45932519999999, longitude: -2.977865299999962),
venueNo:20)
mapView.addAnnotation(artwork20)
centerMapOnLocation(location: initialLocation)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
extension MapContollerViewController: MKMapViewDelegate {
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView,
calloutAccessoryControlTapped control: UIControl) {
//* load page on click
print("button tapped",venueNo)
//working on this
if venueNo == 1{
performSegue(withIdentifier: "Home", sender: self)
}
if venueNo == 2{
performSegue(withIdentifier: "TinSmith", sender: self)
}
}
// 1
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
// 2
guard let annotation = annotation as? Artwork else { return nil }
// 3
let identifier = "marker"
var view: MKMarkerAnnotationView
// 4
if let dequeuedView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
as? MKMarkerAnnotationView {
dequeuedView.annotation = annotation
view = dequeuedView
} else {
// 5
view = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: identifier)
view.canShowCallout = true
view.calloutOffset = CGPoint(x: -5, y: 5)
view.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
}
return view
}
}
以及处理注释的脚本
import Foundation
import MapKit
import Contacts
class Artwork: NSObject, MKAnnotation {
let title: String?
let locationName: String
let discipline: String
let coordinate: CLLocationCoordinate2D
let venueNo: Int
init(title: String, locationName: String, discipline: String, coordinate: CLLocationCoordinate2D, venueNo : Int) {
self.title = title
self.locationName = locationName
self.discipline = discipline
self.coordinate = coordinate
self.venueNo = (venueNo)
super.init()
}
var subtitle: String? {
return locationName
}
}
我对 Swift 很陌生,如果有人能提供帮助,我会很高兴。我已经尝试解决这个问题 5 天了,所以我想寻求帮助。
最佳答案
您可以根据艺术品的venueNo 属性来区分注释:
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView,
calloutAccessoryControlTapped control: UIControl) {
guard let artwork = view.annotation as? Artwork else { return }
let annotaionVenueNo = artwork.venueNo
print("veneueNo = %d", annotaionVenueNo)
// do additional process depend on annotaionVenueNo
}
关于ios - 根据所选注释对各个页面进行 Mapkit 标注,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47444115/
我有一条短线 (MKPolyline) 和一个自定义注释类 (MKPointAnnotaion)。现在我的点注释位于多段线的中点。但是,我希望每当触摸多段线上的任何点时都显示标注,类似于路由在 map
我正在使用此自定义 MKAnnotationView http://blog.asolutions.com/2010/09/building-custom-map-annotation-callout
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicates: Custom MKPinAnnotation callout bubble similar to default
为什么这不起作用? - (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views { if (TRAC
我试图在不触摸引脚的情况下隐藏 AnnotationView,这可能吗?谢谢! for (id currentAnnotation in self.mapView.annotations) {
我正在使用 JQplot 饼图。我需要标 checkout 现在图表之外。我怎样才能做到这一点? 最佳答案 如果您指的是数据标签,则需要将 dataLabelPositionFactor 设置为大于
我的 map 上有 20 个图钉,点击后每个图钉都会显示带有 field 名称的注释,并且右侧有一个标注按钮。我已使用 segue 成功将此按钮链接到单个页面。问题是所有位置都链接到同一页面。我想要
是否可以像在 iPhone 和 Google map 中那样将标注附加到 ItemizedOverlay 项目? 最佳答案 我假设“标注”是指通常出现的信息窗口/“气球提示”?这是代码和示例: htt
我正在使用 Python 2.7 和 PySide(Qt 包装器)开发 GUI 应用程序。 我希望标注小部件 float 在其他小部件上方(类似于工具提示),但不使用标准工具提示框架,该框架基本上为小
我有一个 TableView,用于在点击单元格时显示 MapView 注释标注。 在 iOS 10 中,我可以将 MapView 置于注释的中心,然后使用以下方法显示它的标注: func tableV
我想创建一个自定义 MKAnnotationView 标注,如此图所示。我已经测试了几种解决方案,但它们只允许自定义左/右图像和标题/副标题。谁能给我一些源代码或教程链接吗? 目前我一无所知。请帮忙。
我一直在寻找可能是这个问题的根源,但我看不出出了什么问题。我希望你能在这里帮助我。 我正在尝试在 mapView 中显示注释,图钉被丢弃但无法看到标注,直到我先点击用户位置注释(蓝点)然后返回并点击注
我需要将 xml 数据转换为 Excel 文件。当我写入文件时,我的代码可以正常工作,但是,当我尝试写入输出流时,代码无法正常工作。 我想做的就是使用 Apache POI 类创建一个 excel 文
如何始终在 map View 中显示标注?如果我们点击 map View 标注隐藏并再次点击图钉显示。我不想这样......,我需要始终显示标注,没有隐藏。这个怎么做。请帮我。我正在使用下面的代码来显
我有一个MKPointAnnotation: let ann = MKPointAnnotation() self.ann.coordinate = annLoc self.ann.title = "
我已遵循指南here创建自定义标注 View 。我在自定义类中添加了两行: var dismissesAutomatically: Bool = false var isAnchoredToAnnot
我们正在 Angular.js 中做一个项目,我们从用户体验人员那里获得的模型大量使用交互式弹出窗口/标注。 问题是我似乎无法以干净的方式将这些映射到 Angular 概念上。从概念上讲,它们需要自己
我在显示注释标题时遇到问题,如下图所示。第一张图片很好地表示了值(value);另一方面,一旦值上升到三位数,标题就会显示三个点,如第二张图片所示。我想知道如何解决这个问题。任何想法都将非常受欢迎!非
我正在分析几百万封电子邮件。我的目标是能够分类然后分组。组可以是例如: 交付问题(交付缓慢、发货前处理缓慢、可用性信息不正确等) 客户服务问题(电子邮件回复速度慢、回复不礼貌等) 返回问题(返回请求处
我有一个MKPointAnnotation: let ann = MKPointAnnotation() self.ann.coordinate = annLoc self.ann.title = "
我是一名优秀的程序员,十分优秀!