Adjusting map view span to annotiation pins in Swift - ios

I wonder if Swift supports any faster way to do that without implementing arythmetics. I guess adjusting the map span to let user see all the annotation pins is not a rare problem.
I found this: Zooming MKMapView to fit annotation pins?
but it's a bit complicated in objective-c and seems to be a vulnerable solution. Did swift developers find any other way(or method) to deal with it?
Thanks in advance

If you can target iOS 7 or above, you can use showAnnotations:animated, and pass in the map view's annotation property.

Related

How to add compass or rotation to MapKit Map with SwiftUI

I need to add Compass or rotation with Map. This is my code. I am using Custom marker. I know we can add compass with MKMapView. But I have added many features to the Map using Map class like custom View Markers, longPress pin drop etc. Therefore, moving to MKMapView would be like redoing everything from scratch again.
Map(coordinateRegion: $mapRegion , annotationItems: viewModel.locations) { location in
MapAnnotation(coordinate: location.coordinate) {
MarkerView(location: location)
}
}
Anybody can tell me how I can do compass rotation with Map.
Thanks
You may be able to set these properties on the underlying view via the Introspect framework. It does not handle Map() out of the box, so you would have to follow the section on implementing your own selector. As the project's Read Me states, there are some caveats:
Please note that this introspection method might break in future SwiftUI releases. Future implementations might not use the same hierarchy, or might not use UIKit elements that are being looked for. Though the library is unlikely to crash, the .introspect() method will not be called in those cases.
I have also found that you need to really be careful and heavily test which property you set (or update) when and where.

How to keep an MKAnnotation View Image fixed on the center of the map as the user pans and moves the map around (Swift)?

using target 8.0 MapKit, I would like to define an MKAnnotation (such as a pin, or a custom one) that remains fixed on the center of the map view as the user moves the map around. Once the user stops moving the map, I would like to be able to read the new coordinates of the annotation. How can I do this? This in swift, thank you soo much
You can follow this link to accomplish this task.They are doing something very similar to your requirement. Its quite descriptive. Link

iOS Disable scroll for map view ONLY while zooming

I am currently trying to look for a solution for disabling scrolling on a MKMapView while a person is zooming in/out. Does anyone know of a solution to this? Thanks!
I would check out this control which keeps the map centered on a point when zooming and it sounds like it should be able to achieve you desired effect. I'm not sure if you're using Objective-C or Swift since there is no tag, however you will be able to use this with either languages.
SKMapsCenter

MapKit overlays to add floor plans to map

I am trying to add an overlay to iOS MapKit in order to show floor plans. However, I am unsure about the best way of doing this. If I add the floor plans by using an MKOverlay, will the floor plans be loaded lazily or do I need to find out which part of the map is being displayed and update overlays thereafter? I also looked at using MKTileOverlay, as it is using lazy loading, but I have the impression that it should be used for completely covering of the map and not only to add to the existing one. Is this correct?
Yes, you are right MKTileOverlay can cover whole map with tiles and Yes it is using lazy loading.
Use MKOverlay if you are not willing to replace native look and fill of map. You can also achieve lazy loading for MKOverlay too.
Note: MKTileOverlay will not remove your already existing MKAnnotations and MKOverlay.
MKOverlay is a protocol, not a class. You want MKTileOverlay as of iOS 7. Things are lazy loaded according to what portion of the map is currently shown.
You might find this useful as a reference on how the tiles are numbered and organized:
https://www.mapbox.com/foundations/how-web-maps-work/
As for covering Apple's map, this will happen by default, but you can also adjust the MKOverlayLevel used to place it between Apple's base map and labels layer, or you can use canReplaceMapContent = YES if you want to disable Apple's maps entirely.

How to add Annotation pin for source and destination in iOS using two color?

I am developing a small project, which will display the source and distance trace route, I did complete till that, now the thing is I am unable to add two annotation pin of different color for source and destination, suppose I am using red for source and green for destination.
This might be huge help for everybody who are learning and working.
Thanks
You could use images for your pins or you could use a subclass of MKAnnotationView - MKPinAnnotationView and just change the pinColor property, it's documentation can be found here:
http://developer.apple.com/library/ios/#DOCUMENTATION/MapKit/Reference/MKPinAnnotationView_Class/Reference/Reference.html#//apple_ref/occ/cl/MKPinAnnotationView

Resources