新编码器,试图弄清楚如何使用MapKit.目标是创建一个地图,用户可以使用他们的地址添加引脚.但是,我现在的步骤,我很难搞清楚如何将地图添加到地图.
如何在地图上添加图钉?到目前为止,我一直在努力弄清楚如何使用注释.
这就是我希望得到帮助/指导的方式.谢谢!
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate
{
@IBOutlet weak var bigMap: MKMapView!
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
self.bigMap.showsUserLocation = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations.last
let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.02, longitudeDelta: 0.02))
self.bigMap.setRegion(region, animated: true)
self.locationManager.stopUpdatingLocation() …Run Code Online (Sandbox Code Playgroud) 当我尝试放置一个引脚时,我在使用自定义注释加载到地图视图中时遇到了一些麻烦.
import UIKit
import MapKit
import CoreLocation
class MapViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate{
@IBAction func ReportBtn(sender: AnyObject) {
//MARK: Report Date And Time Details
let ReportTime = NSDate()
let TimeStamp = NSDateFormatter()
TimeStamp.timeStyle = NSDateFormatterStyle.ShortStyle
TimeStamp.dateStyle = NSDateFormatterStyle.ShortStyle
TimeStamp.stringFromDate(ReportTime)
//MARK: Default Point Annotation Begins
let ReportAnnotation = MKPointAnnotation()
ReportAnnotation.title = "Annotation Created"
ReportAnnotation.subtitle = ReportTime.description
ReportAnnotation.coordinate = locationManager.location!.coordinate
mapView(MainMap, viewForAnnotation: ReportAnnotation)
MainMap.addAnnotation(ReportAnnotation)
}
@IBOutlet weak var MainMap: MKMapView!
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.delegate = self …Run Code Online (Sandbox Code Playgroud) 我有一个纬度数组和另一个经度数组,我添加到CLLocationCoordinate2D类型的数组.然后我使用新数组来注释地图上的多个点.一些,或大多数,甚至所有注释都在地图上显示但是当我放大(是的,放大IN)时,一些注释消失,然后回来,或者不.关于如何让它们全部可见的任何想法?这是我在缩小时所期望的行为,而不是.
这是我用于上述内容的代码.
import UIKit
import MapKit
import CoreLocation
class MultiMapVC: UIViewController, CLLocationManagerDelegate {
@IBOutlet weak var multiEventMap: MKMapView!
var latDouble = Double()
var longDouble = Double()
let manager = CLLocationManager()
var receivedArrayOfLats = [Double]()
var receivedArrayOfLongs = [Double]()
var locations = [CLLocationCoordinate2D]()
func locationManager(_ manager: CLLocationManager, didUpdateLocations uLocation: [CLLocation]) {
let userLocation = uLocation[0]
let span:MKCoordinateSpan = MKCoordinateSpanMake(0.3, 0.3)
let usersLocation = userLocation.coordinate
let region:MKCoordinateRegion = MKCoordinateRegionMake(usersLocation, span)
multiEventMap.setRegion(region, animated: true)
manager.distanceFilter = 1000
self.multiEventMap.showsUserLocation = true
}
func multiPoint() …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用MKOverlay(特别是一个MKPolyline)在地图上显示路线.但是,我需要路线显示在我现有的引脚(自定义MKAnnotationViews)之上.有没有一种好方法可以将MKPolyline引脚放在引脚上方?
在IOS中我有一个带有几个MKAnnotation的地图,点击其中一个我看到带有文本的气泡,但是文本太长,然后它没有完整显示.
我正在寻找一种在多行TextView或类似的东西中显示文本的方法,以便完全显示.
我正在使用Alamofire并SwiftyJSON自动填写Google商家信息.我把它整合得很好,就像这样:
现在,我需要的是如果我从表格视图中选择一个地方,它将在文本字段中被选中.但是如何获得该地点的相应纬度和经度,以便我可以在MapKit中添加该地点的注释
从Google Place APIApple的MapKit 获取细节并显示它们是否合法?在看到Viking的问题之后,我对此产生了怀疑
我需要你的帮助,我正在开发一个应用程序,我有一些引脚(位置),我想要的是获得每个和我的位置之间的距离.我的代码如下
let annotation = MKPointAnnotation()
let annotationTwo = MKPointAnnotation()
let saintPaulHospitalBC = MKPointAnnotation()
override func viewDidLoad() {
super.viewDidLoad()
mapita.showsUserLocation = true // Mapita is the name of the MapView.
annotation.coordinate = CLLocationCoordinate2D(latitude: 25.647399800, longitude: -100.334304500)
mapita.addAnnotation(annotation)
annotationTwo.coordinate = CLLocationCoordinate2D(latitude: 25.589339000, longitude: -100.257724800)
mapita.addAnnotation(annotationTwo)
saintPaulHospitalBC.coordinate = CLLocationCoordinate2D(latitude: 49.280524700, longitude: -123.128232600)
mapita.addAnnotation(SaintPaulHospitalBC)
}
Run Code Online (Sandbox Code Playgroud)
当我运行代码时,地图显示了引脚,但我还能做些什么才能开始计算距离?谢谢!
我有MKMapView几个注释,其中 3 个注释彼此非常接近。
我曾经mapView.showAnnotations(mapView.annotations, animated: false)在启动时显示同一区域上的所有注释,但 3 个注释之一被隐藏,因为它太接近了。
我查看了Apple的文档,但找不到防止这种情况发生的方法,知道如何防止注释分组吗?
(我以前从未见过这个,也许这是iOS 11的功能)
我正在尝试注册自定义注释视图(我将它们创建为 MKAnnotationView 的子类),但是我遇到了一些麻烦。最初,我尝试使用以下代码为单个注释标记仅注册一个自定义注释视图(RestaurantMarkerView 是我的自定义注释视图):
mapView.register(RestaurantMarkerView.self, forAnnotationViewWithReuseIdentifier: MKMapViewDefaultAnnotationViewReuseIdentifier)
Run Code Online (Sandbox Code Playgroud)
它工作正常(当我点击图钉时,它会显示标注)。现在我添加另一个注释标记并尝试为其注册另一个视图,据我所知,在这种情况下,我应该为视图使用自定义标识符,因此我通过以下代码执行此操作:
mapView.register(RestaurantMarkerView.self, forAnnotationViewWithReuseIdentifier: "a")
mapView.register(ChoosenRestaurantMarkerView.self, forAnnotationViewWithReuseIdentifier: "b")
Run Code Online (Sandbox Code Playgroud)
现在,当我点击标记时,它们不会显示标注。当我将其中一个标记的重用标识符更改为 时MKMapViewDefaultAnnotationViewReuseIdentifier,该标记会显示标注。那么,如何注册多个自定义注释视图?谢谢。
我正在尝试在地图中的图钉顶部显示自定义呼叫。我需要在图钉顶部显示带有一些文字的图像作为我的呼唤。我编写的代码产生以下输出。
但是,我想要的输出如下所示:
我怎样才能达到我想要的输出?请注意,气泡是必须使用的图像资产,我知道如何使用 CAShapeLayer 绘制气泡,但这并不能完成我想要的。这是到目前为止的代码。
// methods for Custom annotations
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let annotationView = MKAnnotationView(annotation: pin, reuseIdentifier: "UserLocation")
annotationView.image = UIImage(named: "marker")
annotationView.canShowCallout = true
configureDetailView(annotationView: annotationView)
return annotationView
}
func configureDetailView(annotationView: MKAnnotationView) {
let width = 300
let height = 200
let calloutView = UIView()
calloutView.translatesAutoresizingMaskIntoConstraints = false
let views = ["calloutView": calloutView]
calloutView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:[calloutView(300)]", options: [], metrics: nil, views: views))
calloutView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:[calloutView(200)]", options: [], metrics: nil, views: views))
let …Run Code Online (Sandbox Code Playgroud) ios ×10
mapkitannotation ×10
mapkit ×9
swift ×8
alamofire ×1
geolocation ×1
mkannotation ×1
mkoverlay ×1
objective-c ×1