mapkit

Show user location on map SwiftUI

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-23 11:45:11
问题 I am trying to load a map and have the initial location on user's location as well as showing the user's location on the map using SwiftUI. I don't know how to do that in SwiftUI. I have tried to put 'view.showsUserLocation = true' in updateUIView function but it is not working. import SwiftUI import MapKit struct MapView : UIViewRepresentable { func makeUIView(context: Context) -> MKMapView { MKMapView(frame: .zero) } func updateUIView(_ view: MKMapView, context: Context) { view

Show user location on map SwiftUI

时光怂恿深爱的人放手 提交于 2020-01-23 11:45:06
问题 I am trying to load a map and have the initial location on user's location as well as showing the user's location on the map using SwiftUI. I don't know how to do that in SwiftUI. I have tried to put 'view.showsUserLocation = true' in updateUIView function but it is not working. import SwiftUI import MapKit struct MapView : UIViewRepresentable { func makeUIView(context: Context) -> MKMapView { MKMapView(frame: .zero) } func updateUIView(_ view: MKMapView, context: Context) { view

ios 7 MKMapView draggable annotation change it's position when map is scrolled

这一生的挚爱 提交于 2020-01-23 07:47:01
问题 I am updating my app (MyWorld) to iOS 7. One of the features of the app is that you can drag pin on the map view. It seems to be broken in iOS7. Steps to recreate the problem: Adding Annotation to the map: - works fine Moving Annotation (Dragging) works fine Scrolling the map: Problem Whenever I scroll the map view annotation is moved with the map. It seems like it's not attached to the right view or layer?? If the pin is not dragged map view seems to work fine and annotation stays in defined

MKMapPoint with MKMapPointMake from MKMapRect

ぃ、小莉子 提交于 2020-01-23 03:37:25
问题 I have the following code: MKMapRect mRect = self.mapView.visibleMapRect; MKMapPoint eastMapPoint = MKMapPointMake(MKMapRectGetMaxX(mRect), MKMapRectGetMaxY(mRect)/2); MKMapPoint northMapPoint = MKMapPointMake(MKMapRectGetMaxX(mRect)/2, 0); MKMapPoint southMapPoint = MKMapPointMake(MKMapRectGetMaxX(mRect)/2, MKMapRectGetMaxY(mRect)); MKMapPoint westMapPoint = MKMapPointMake(0, MKMapRectGetMaxY(mRect)/2); I am converting these to CLLocationCoordinate2D with MKCoordinateForMapPoint . For

How do I overlay a circle at a set location using mapkit and swift

走远了吗. 提交于 2020-01-23 01:33:06
问题 I am having trouble trying to figure out how to display a transparent circle or rectangle at a desired location unique from the users location. Im a beginner with mapkit so thanks in advance. class FirstViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate { @IBOutlet weak var mapView: MKMapView! let locationManager = CLLocationManager() override func viewDidLoad() { super.viewDidLoad() self.locationManager.delegate = self self.locationManager.desiredAccuracy =

MKOverlay not resizing smoothly

你。 提交于 2020-01-19 23:22:44
问题 I have added a MKCircle as MKOverlay to my MKMapView. Also I added an UISlider to decide the radius of the circle. Unfortunately when using this it seems a bit "laggy", not smootly like I want it to be. Example: http://dl.dropbox.com/u/3077127/mkoverlayDelay.mov This is my code: - (void)addCircle { // draw the radius circle for the marker double radius = 2000.0; MKCircle *circle = [MKCircle circleWithCenterCoordinate:location radius:radius]; [circle setTitle:@"background"]; [mapView

How do I add custom pins to the iPhone MapKit?

扶醉桌前 提交于 2020-01-19 05:24:25
问题 I'm testing out the MapKit framework on the iPhone and would really much like to switch the standard pin that displays a location to an image called "location.png". How can I modify my code to allow that? Maincontroller - (void)viewDidLoad { [super viewDidLoad]; // // Set the map center // CLLocationCoordinate2D coordinate; coordinate.latitude = 49.2802; coordinate.longitude = -123.1182; mapView.region = MKCoordinateRegionMakeWithDistance(coordinate, 2000, 2000); // // Set 10 random locations

How to create custom pin annotation view

萝らか妹 提交于 2020-01-17 14:51:48
问题 I have a map I'm populating with a list of food trucks, and I'd like to implement a custom callout like the one shown below, when an annotation is selected. Currently I have the standard annotation callout implemented with a title and subtitle. I've done some reading and am guessing it'll require a custom .xib file, but I don't really know anything about this as I only started developing for iOS as a recently. How would I go about creating this custom popup, and how can I make it perform a

Swift how to fill in overlay with a new color

筅森魡賤 提交于 2020-01-17 05:48:11
问题 I am having trouble filling in the overlay. I would like to use a new color. Thanks for the help in advance. func addBoundry() { var points=[CLLocationCoordinate2DMake(39.02, -76.9),CLLocationCoordinate2DMake(38.97, -76.9),CLLocationCoordinate2DMake(38.97, -77),CLLocationCoordinate2DMake(39.02, -77)] let polygon = MKPolygon(coordinates: &points, count: points.count) mapView.addOverlay(polygon) } let regionRadius: CLLocationDistance = 1000 func centerMapOnLocation(location: CLLocation) { let

MKDirections calculateETAWithCompletionHandler executing with delay Swift 2.0

孤街醉人 提交于 2020-01-16 03:57:27
问题 I'm trying to calculate the ETA between two coordinates in Swift using calculateETAWithCompletionHandler from the MKDirections class. I have the following code in my program, MapViewController.swift print("A") calculateETAofClosestBus(closestBusStop) print("B") func calculateETAofClosestBus(destination: BusStop) { var shortestETA = 0 print("C") var request = MKDirectionsRequest() var sourceItem = MKMapItem(placemark: MKPlacemark(coordinate: listBuses[0].pin.coordinate, addressDictionary: nil)