Look at what this code is doing: var placeMarks: NSMutableArray = NSMutableArray() for mp in placeMarks{ placeMarks.addObject(mp) } First, it creates and initializes an empty array called placeMarks. Then, it loops through placeMarks (which is empty) and adds its own objects to itself (but that code never executes because the...
ios,mapkit,mkmapitem,mkplacemark
You should call the openInMaps only when the MKMapViewDelegate is called on didSelectAnnotation: for ex. https://developer.apple.com/library/ios/documentation/MapKit/Reference/MKMapViewDelegate_Protocol/index.html#//apple_ref/occ/intf/MKMapViewDelegate To open the Maps app you could also build the URL yourself with the following: UIApplication.sharedApplication().openURL(...) Check this documentation here for the rest: https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html...
ios,objective-c,mapkit,objective
As I understood, you need to know what Address was found by async request. You are using block to obtain a callback, so you can just use variables from outer scope in the block, it will capture the reference until finishes. NSArray *adresses = @[ @{@"adress":@"Kyiv, Gorkogo 17"}, @{@"adress":@"New York"}...
There are two different delegate methods: mapView:rendererForOverlay:, which was introduced in iOS 7, and returns a MKOverlayRenderer; and mapView:viewForOverlay:, which was deprecated in iOS 7, but it returns a MKOverlayView, not a MKOverlayRenderer. It is incorrect to implement a viewForOverlay that returns a MKOverlayRenderer. Bottom line, if you need to...
objective-c,osx,mkmapview,mapkit,mkannotation
I figured out what was wrong. I was subclassing MKMapView, which is apparently not recommended by Apple, as it can cause some unwanted behavior.
ios,objective-c,mapkit,cllocationmanager
In order to request extra time for your app to run in the background to complete its tasks (asynchronous or not), you can use beginBackgroundTaskWithExpirationHandler:. For example: - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { // If the application is in the background... if([[UIApplication sharedApplication] applicationState] != UIApplicationStateActive) { //...
It's because your annotation view only detects touches inside its bounds. Since your callout view extends beyond the bounds, the subview doesn't recognize the tap. You need to override the pointInside:withEvent: method in the annotation view so your callout will actually detect the touch. Here's an example in Objective-C: -...
Try this: for step in self.route!.steps as [MKRouteStep] { otherwise it treats step as AnyObject (which doesn't have a polyline property defined so you get that compiler error). By the way, note that polyline.coordinate just gives the average center of the polyline or one endpoint. A polyline can have more...
You need to make a MKDirections request. From calculateDirectionsWithCompletionHandler you will get a MKDirectionsResponse. This has a routes array of MKRoutes. Each route has a distance (i.e. road distance) property. var source = MKMapItem( placemark: MKPlacemark( coordinate: CLLocationCoordinate2DMake(-41.27, 173.28), addressDictionary: nil)) var destination = MKMapItem(placemark: MKPlacemark( coordinate: CLLocationCoordinate2DMake(-41.11, 173), addressDictionary:...
Are you sure you are using the return address after completion block? I have used the above code and its working fine. Here you can download the sample code CLGeocoder *geoCoder = [[CLGeocoder alloc]init]; __block NSString *returnAddress = nil; CLLocation *locloc = [[CLLocation alloc] initWithLatitude:12.92243 longitude:80.23893]; [geoCoder reverseGeocodeLocation:locloc completionHandler:^(NSArray *placemarks,...
Add this to your plist <key>NSLocationAlwaysUsageDescription</key> <string></string> <key>NSLocationWhenInUseUsageDescription</key> <string></string> And this lines of code #define IS_OS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) if(IS_OS_8_OR_LATER) { [locationManager requestAlwaysAuthorization]; } This worked for me. Hope will work for you too :)...
ios,objective-c,mapkit,objective-c-blocks
I believe the way you are making use of MKMapItem is the problem, you need to run this on the main thread. So I don't think it will work for what you need. When collecting the location in the background you should use CoreLocation instead.
mapkit,core-location,cllocationmanager
In iOS 8, you can check the current permission that you get from the user. If the user gives you an Always permission, that means that they allow significant location changes. If they only allow WhenInUse, they don't allow significant location changes. See this post for details on what you...
The authoritative way to do this is to pass includeMetadata:NO and you won't get this starting info: https://www.mapbox.com/mbxmapkit/api/Classes/MBXRasterTileOverlay.html#//api/name/initWithMapID:includeMetadata:includeMarkers:...
ios,google-maps,geolocation,mapkit,reverse-geocoding
A solution is to change the way your data is structured. When a user checks in, besides storing a coordinate, store data such as the city, state, or country associated with the coordinate. Doing it this way, each user would reverse geocode a coordinate before checking in.
ios,objective-c,mapkit,mapkitannotation
You could just create your own annotation view: #import <MapKit/MapKit.h> @interface CustomAnnotationView : MKAnnotationView @property (nonatomic, weak) UILabel *label; @end and @interface CustomAnnotationView () @property (nonatomic) CGFloat width; @end @implementation CustomAnnotationView - (instancetype)initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier]; if (self) { UILabel *label = [[UILabel alloc] init];...
ios,google-maps,mapkit,google-street-view
Once check whether all the files are added correctly into your App.check in BuildPhases also if anything is missed.Hope this helps.
Your assumption is wrong. You can generate a request for driving directions using lat/long coordinates just as easily as using addresses. Here's what you do: Get the MKMapItem for the user-selected pin Create a second MKMapItem for the user's current location using the MKMapItem method mapItemForCurrentLocation(). Call the MKMapItem class...
You have to use MKPolylineRenderer for iOS 8 Following is the code for adding MKPolyline by tapping on locations may you get help. Pin.h #import <Foundation/Foundation.h> @import MapKit; @interface Pin : NSObject <MKAnnotation> @property (nonatomic, readonly) CLLocationCoordinate2D coordinate; @property (nonatomic, copy) NSString *title; @property (nonatomic, copy) NSString *subtitle; - (id)initWithCoordinate:(CLLocationCoordinate2D)newCoordinate;...
If I get it right. You want to change blue dot. Try this. let theLocation: MKUserLocation = theMap.userLocation theLocation.title = "I'm here!" ...
You are doing it right.You just need to have these methods implemented for adding button along with title and subtitle import UIKit import MapKit import CoreLocation class MapKitViewController: UIViewController, MKMapViewDelegate { let locationManager = CLLocationManager() @IBOutlet weak var nmapView: MKMapView! override func viewDidLoad() { super.viewDidLoad() locationManager.requestWhenInUseAuthorization() locationManager.startUpdatingLocation() let location =...
It's because you're confusing views and view controllers. You have a view (subclass of MKMapView, but you're naming it and trying to use it as a controller. It is also doings the job of a controller. So, you should really have a view controller which owns and configures a map...
I ended up solving my own question. I just added this line of code in viewDidLoad: [self.locationManager requestWhenInUseAuthorization]; This was very helpful: http://nevan.net/2014/09/core-location-manager-changes-in-ios-8/...
objective-c,xcode,swift,mapkit,mkannotation
The "forced cast" as MKPinAnnotationView (to a non-optional type) aborts with a runtime exception if mapView.dequeueReusableAnnotationViewWithIdentifier() returns nil. You can use an optional cast as? instead: annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier("cluster") as? MKPinAnnotationView which assigns nil to annotationView in that case. If it is guaranteed that all elements in the reuse queue...
Use a for loop and create an MKDirectionsRequest for each destination in your set (or array). As each completion handler block gets called, store the result in a set or (array). I have sent multiple requests 'rapid fire' like this to get directions and have not been throttled.
Rather than init, call the MKCircleRenderer method initWithCircle. Obviously, make sure the delegate of the map view is set, that your code that adds the overlay and that instantiates the renderer is called at all, etc., but initWithCircle is the likely culprit. ...
swift,mkmapview,mapkit,mkannotation,mkannotationview
You need create a MKPointAnnotation a then call the method for example var info1 = CustomPointAnnotation() info1.coordinate = CLLocationCoordinate2DMake(20.646696, -103.398744) info1.title = "Title" info1.subtitle = "More Info" info1.imageName = "iphonepin.png" propMapa.addAnnotation(info1) propMapa.selectAnnotation(info1, animated: true) CustomPointAnnotation is a custom class and extends from MKPointAnnotation...
The location property of CLLocationManager is declared as: @NSCopying var location: CLLocation! { get } and thus your let location could be filled with a nil value. Perhaps this declaration changed recently as Apple scrubs their interfaces related to optionals. You'll need to bind your latitude and longitude while respecting...
ios,xcode,frameworks,mapkit,core-location
When you enabled the "Maps" availability. Xcode automatically linked MapKit for you. ...
This is because you are resetting the location every time the user's location changes. You should do this only once, e.g. -(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation { if (self.centerToUserLocation) { MKCoordinateRegion mapRegion; mapRegion.center = self.mapView.userLocation.coordinate; mapRegion.span = MKCoordinateSpanMake(0.5, 0.5); //Zoom distance [self.mapView setRegion:mapRegion animated: YES]; self.centerToUserLocation = NO; } } Where...
The problem is this line: let userLocation = routeMap.userLocation The result, userLocation might be nil, and its location might be nil, because the map might not have been told to, or succeeded in acquiring, the user's location. You are not taking into account that possibility. The way to do that...
ios,iphone,mkmapview,mapkit,openstreetmap
The format of the response is regular XML. For understanding it you should read about OSM's elements. Your response contains one way and several nodes as well as their tags. But it could contain more than a single way when querying a different bounding box. The way has a maxspeed...
ios,cocoa-touch,mkmapview,mapkit,cllocationmanager
I prefer to use CLLocationManager which is used internally by the MKMapView, so if you don't need to use the map, just use the below code from the location manager. locationManager = [[CLLocationManager alloc] init]; locationManager.distanceFilter = kCLDistanceFilterNone; locationManager.desiredAccuracy = kCLLocationAccuracyBest; locationManager.delegate = self; [locationManager startUpdatingLocation]; Just don't forget to...
ios,navigation,mapkit,directions,mkpolyline
Since no one has answered to my question I am answering it myself so that it may help someone looking for the same. So instead of using distance value of MKRouteStep to calculate when to show next instruction, we can use the last coordinate of polyline array provided by MKRouteStep....
ios,xcode,swift,mapkit,cllocation
You just need to declare you var startLocation as an optional but not inside your function. var startLocation :CLLocation! then inside your didUpdate function you just test if the startLocation var is nil: func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) { if startLocation == nil { startLocation = locations.first as? CLLocation...
MKMapView Class Reference : http://goo.gl/djHXPn Look at the camera property : A camera object defines a point above the map’s surface from which to view the map. Applying a camera to a map has the effect of giving the map a 3D-like appearance. You can use a camera to rotate...
ios,xcode,uitableview,swift,mapkit
This message only occurs if you connect it to the view controller. As I have already commented, you probably did not delete the first connection outlet you've made to your view controller. Even if you delete the IBOutlet code from your view controller you still need to right click it...
ios,iphone,swift,mapkit,mapkitannotation
You shouldn't override function performSegueWithIdentifier just prepareForSegue Also the prepareForSegue method your implementation is wrong (if you are trying to pass some arguments into destination view controller). You need something like this let vc = segue.destinationViewController as! MapRouteViewController ...
You can call startUpdatingLocation() or stopUpdatingLocation() from inside of any method. First You must create location manager within your class, class let locationManager = CLLocationManager() func initializeLocationManager() { locationManager.delegate = self locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation locationManager.pausesLocationUpdatesAutomatically = false locationManager.distanceFilter=kCLLocationAccuracyNearestTenMeters } func anyMethod() { locationManager.stopUpdatingLocation()...
I used following code from google map SDK to get the tap location- - (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate { NSLog(@"You tapped at %f,%f", coordinate.latitude, coordinate.longitude); [mMapview clear]; gpsLocation = [[CLLocation alloc]initWithLatitude:coordinate.latitude longitude:coordinate.longitude]; } And with following code I am dropping the pin on that location- GMSMarker *marker = [[GMSMarker alloc]init]; marker.title...
ios,swift,annotations,mapkit,coordinates
I have solved my problem by creating custom annotation class like below - import UIKit import MapKit var ARROW_ANNOTATION : NSString = "ARROW_ANNOTATION" var PIN_ANNOTATION : NSString = "PIN_ANNOTATION" class Annotation: NSObject, MKAnnotation { var currentLocation: CLLocationCoordinate2D var _title : String var subTitle : String var direction : CLLocationDirection! var...
ios,xcode,swift,mapkit,core-location
Your didload method is getting called before the didAppear method. Therefore, your location manager is not initialized yet. So you need to initialize it before using it.
Yes, you're on the right track. This is the full code: let places = [place(name: "Eiffel Tower", latitude: 48.8582, longitude: 2.2945), place(name: "Statue of Liberty", latitude: 40.6892, longitude: -74.0444), place(name: "Tower of London", latitude: 51.5081, longitude: -0.0761)] let annotations = places.map { aPlace -> MKPointAnnotation in let annotation = MKPointAnnotation()...
You're getting default pins "randomly" because of this code: MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier]; if (annotationView) return nil; What this code says is if the dequeueReusableAnnotationViewWithIdentifier: returns a view (ie. if annotationView is not nil), return nil from the delegate method. When you return nil from the viewForAnnotation delegate method,...
Your problem is that you are adding an MKAnnotationView to the map rather than an MKAnnotation - You either need to add an instance of a class that implements the MKAnnotation protocol or an MKPointAnnotation
ios,objective-c,mapkit,mkannotation,mkannotationview
Option 1 Try changing this line: static NSString* AnnotationIdentifier = @"AnnotationIdentifier"; To this: NSString* AnnotationIdentifier = annotation.type; Option 2: After this line: MKAnnotationView *annotationView = [mapview dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier]; Add this line: annotationView.image = [self setImageByType:annotation]; ...
I would expect That's your problem right there. CLPlacemarks obtained by reverse geocoding categorize their pieces the way they categorize them, not the way you expect. So the solution here is to stop expecting and start dealing with the placemark so that you can obtain the results you want....
This seems to be a bug which can be workarounded in different ways. The rightCalloutAccessoryView vertical alignment can be fixed by simply setting the autoresizingMask as follows: UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeInfoLight]; rightButton.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin; annotationView.rightCalloutAccessoryView = rightButton; The same trick does not work with the leftCalloutAccessoryView which...
ios,mkmapview,mapkit,deprecated,mkpolyline
See the documentation for initWithPolyline:. Read the Deprecation Statement which says to use an MKPolylineRenderer object instead.
ios,swift,mapkit,cllocationmanager
if you were to choose "No" when it requests, I want to be able to then turn it back on again Once the user has chosen to refuse you authorization, you cannot magically contradict the user, and (alas) you cannot make the system's authorization dialog appear ever again. The...
Yes, the wrong tap point values are being passed to CGPathContainsPoint. The values in the overlay renderer's path are not in screen CGPoint units. The path contains values that correspond to the renderer's own drawing context which is different from the screen. You need to first convert the tap point...
ios,objective-c,cocoa-touch,mapkit,mkannotationview
For this section: if(!pinView) { pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomViewAnnotation"]; pinView.canShowCallout = YES; pinView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@Annotation", [annotation title]]]; } else { pinView.annotation = annotation; } Add the line: pinView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@Annotation", [annotation title]]]; Also for the else, so it will look like that: if(!pinView) {...
Yes, the fee is effectively included in your $99 Developer Program fee and the 30% cut of sales.
ios,swift,mapkit,mkuserlocation
You want to put an accessory button on the callout of the blue dot (user location). In the viewForAnnotation delegate method, you do have code that creates an annotation view and sets the rightCalloutAccessoryView but at the top of the method there is this code: func mapView(Mapa: MKMapView!, viewForAnnotation annotation:...
swift,annotations,mapkit,mklocalsearch
For the first issue: A callout button needs to be set explicitly in the viewForAnnotation delegate method (default red pins don't have one). Here's a simple example of one possible implementation: func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! { if annotation is MKUserLocation { return nil } let reuseId...
ios,xcode,swift,mapkit,mkpolyline
After some digging I managed to find the answer to this question, although I'm not really sure about its impact on overall performance of whether or not this going to make Apple happy, since it sends out a lot of small MKDirectionsRequest's. For me 30+ points worked just fine. var...
swift,mapkit,core-location,watchkit
You don't actually have an app running on the Apple Watch. Your app will run in an WatchKit extension running on your iPhone. In your WatchKit extension you can use MapKit to create a route. The difference is that you will need to display your map using WKInterfaceMap in your...
ios,objective-c,mapkit,mkannotationview
In the subtitle method: - (NSString *)subtitle { return _address; return _temperature; } nothing after the return _address; line will execute. That's how a return statement works (execution returns immediately to the caller). Don't confuse the arrangement of the code with how the variables mentioned are displayed in the user...
var myAnnotation = MKPointAnnotation() // ... locations.append(myAnnotation) // ... locations.append(myAnnotation) In the first line, you make one MKPointAnnotation object. An MKPointAnnotation is a class instance - a reference type. myAnnotation is therefore the same object each time. You are just appending two references to it into your array. They are...
MapKit doesn't offer this right now. You might be able to get what you are after by setting up your own GraphServer.
ios,objective-c,annotations,mapkit,uisplitviewcontroller
I've been able to reproduce the issue consistently and it indeed looks like a bug with Apple's mapkit code. The only way i've been able to fix it was to create a singleton for MKMapView -(MKMapView*)mapview{ static MKMapView *_mapview = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ _mapview = [[MKMapView alloc]...
ios,objective-c,mapkit,selector
OK, I managed to prevent the crash with the following fix. When a POI is selected in my list, I trigger a delegate method of the view controller that handles the MapView from the didSelect method of the controller of the tableView. If you have the same problem, I assume...
Answer 2: The first argument of the second (third, fourth) call to the closure is the result output by the previous call to the closure. The only exception is the first call, which has no previous call to inherit from, which is why reduce takes the value 0 as the...
ios,objective-c,parse.com,mapkit
The problem here is that postArray is populated in a background thread and your application initializes faster than it can populate the array. This is common in asynchronous programming. The way to fix this, is by asking the map to refresh in the main thread. - (void)loadLocalPosts { NSLog(@"Querying for...
Have you tried using: func clearTrack(sender: UIButton){ theMap.removeOverlays(theMap.overlays) } ...
I did something like this -(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation { if (!self.initialLocation) { self.initialLocation = userLocation.location; MKCoordinateRegion mapRegion; mapRegion.center = mapView.userLocation.coordinate; mapRegion.span.latitudeDelta = 0.2; mapRegion.span.longitudeDelta = 0.2; [mapView setRegion:mapRegion animated: YES]; } } self.initialLocation is an instance of CLLocation. This method constantly updates the user's current location and so what...
ios,mkmapview,mapkit,mkannotation,mkannotationview
A quite late response, but I guess other people would still be interested In a MKAnnotationView subclass: First, define some dimensions: #define ckImageHeight 65 #define ckImageWidth 55 #define kBorder 5 Then define the Annotation View's frame: self.frame = CGRectMake(0, 0, ckImageWidth, ckImageHeight); If you want the background to be an...
Anna was on the right path. I was creating a new instance of the DetailViewController. I was able to solve it by adding @property (strong, nonatomic) DetailViewController *detailViewController; to the MasterViewController.h. And then just calling [self.detailViewController addPins:woX ycoord:woY desc:cellView]; in MasterViewController.m...
After some hours of research I've found a way to do so. The key property is initialized trough: MKMapCamera *mapCamera = [MKMapCamera cameraLookingAtCenterCoordinate:ground fromEyeCoordinate:eye eyeAltitude:50]; Take a look at this tutorial if you are need of an explanation step by step: http://nscookbook.com/2013/10/ios-programming-recipe-30-using-3d-mapping/...
It looks like your latitude and longitude are swapped between your two samples...
If you are using MKMapView, you should check out the following examples: http://www.meonbinary.com/2014/02/route-directions-with-ios7-mapkit-and-google-maps-api http://sugartin.info/2011/10/12/drawing-route-on-google-map-mkmapview/ If you are using GMSMapView, check out this stack question: Drawing Route Between Two Places on GMSMapView in iOS...
Complex animations or shading/gradients will probably require creating a custom overlay renderer class. These other answers give ideas about how to draw gradient polylines and animations will most like require a custom overlay renderer as well: how to customize MKPolyLineView to draw different style lines Gradient Polyline with MapKit ios...
I'm thinking it's because latitudes range from -90 to 90, and 120 is out of range. Thus you're specifying invalid data. The first number, latitude, ranges from -90 to +90. The second number ranges from -180 to +180....
ios,core-data,mapkit,cllocation,mkmapitem
I would suggest you change the properties of your PointOfInterest subclass back to NSNumber, and then change your assignment of latitude and longitude as follows: newPOI.latitude = [NSNumber numberWithDouble:self.item.placemark.location.coordinate.latitude]; newPOI.longitude = [NSNumber numberWithDouble:self.item.placemark.location.coordinate.longitude]; Then when you want to use the latitude: self.item.placemark.location.coordinate.latitude = [newPOI.latitude doubleValue]; etc....
I believe you need to set the lat and long BEFORE you set the region. The setRegion function is what zooms in on a certain part, and the level of the zoom depends on your span. Here's an example of a map that zooms. var span = MKCoordinateSpanMake(0.075, 0.075) var...
I created the map programmatically instead of using a MapKit View, and it works perfectly! Here's the code: [super viewDidLoad]; self.mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)]; [self.mapView setShowsUserLocation:YES]; [self.mapView setDelegate:self]; [self.view addSubview:self.mapView]; [mapView setMapType:MKMapTypeHybrid]; } #pragma mark - MKMapViewDelegate Methods - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {...
MKLocalSearch with MKLocalSearchRequest is exactly what you are looking for. A basic search can be done as follows: MKLocalSearchRequest *request = [[MKLocalSearchRequest alloc] init]; request.naturalLanguageQuery = @"some address"; MKLocalSearch *localSearch = [[MKLocalSearch alloc] initWithRequest:request]; [localSearch startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error) { // do stuff with the response }]; This should put...
ios,xcode,swift,annotations,mapkit
I can see nothing wrong with your code. The only thing that irritates me is this line: self.annotation.coordinate = location It looks like self.annotation is an instance variable which you reuse for any new annotation. Here is a code snippet from one of my apps where multiple annotations work without...
ios,mkmapview,mapkit,mapkitannotation
In viewForAnnotation, CustomMapAnnotationView is never actually alloc+inited (the dequeueReusableAnnotationViewWithIdentifier does not do this). If viewForAnnotation is even getting called, it must be returning nil which means the map view must be putting a red pin somewhere (and if the delegate method isn't getting called, then again the map view will...
ios,swift,mapkit,core-location
First of all, do not needlessly put a useless CLLocation() into receivedLocation. Declare receivedLocation as an implicitly unwrapped Optional: var receivedLocation : CLLocation! = nil That way, either someone has set it or they have not. If they have not, it is nil, and you can test that: if receivedLocation...
ios,swift,mapkit,watchkit,apple-watch
This code works in an app that I am working on. It also works with the app in the background so I think it's safe to say that MKDirectionsRequest will work in background mode. Also, this is called from the AppDelegate and is wrapped in a beginBackgroundTaskWithName tag. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),...
You need to restructure your code. You want to create an array of all the locations you want to add to the map first. Once you have that, then call addAnnotations (with an "s") to add all the annotations. You will also need to calculate your region based on the...
core-data,mapkit,cllocation,mkmapitem
For every easy question, there's an easy answer: mapItem.placemark.location.coordinate.latitude mapItem.placemark.location.coordinate.latitude ...
ios,xcode,swift,mapkit,mkannotation
If you do not require to change coordinates after initialization then you can use it that way. It works for me with Swift 1.2: class CustomAnnotation : NSObject, MKAnnotation { let coordinate: CLLocationCoordinate2D var title: String init(coordinate: CLLocationCoordinate2D, title: String) { self.coordinate = coordinate self.title = title } } ...
ios,mkmapview,mapkit,mkoverlay
According to Anna's answer you should use [self pointForMapPoint:points[i]] instead of points[i] - (void)createPath { MKPolyline *line = (id)self.overlay; MKMapPoint *points = line.points; NSUInteger pointCount = line.pointCount; CGMutablePathRef path = CGPathCreateMutable(); CGPoint point = [self pointForMapPoint:points[0]]; CGPathMoveToPoint(path, NULL, point.x, point.y); for (int i = 1; i < pointCount; i++) {...
If anyone needs 1.&2.) var mapView = MKMapView() in ViewDidLoad() ....... mapView.mapType = .Standard mapView.frame = view.frame table.tableFooterView = mapView 3.) Use annotations ...
ios,swift,annotations,mapkit,alamofire
If you have two CLLocation instances, you can calculate distance with the following code: var one, two: CLLocation // assign one and two let distance = two.distanceFromLocation(one) CLLocationDistance is just double and distance calculated in meters...
Remember to set the masksToBounds property of the layer to YES, in addition to setting a corner radius.
Well I still don't know why in iOS7 MKMapView.convertPoint(MKMapView.center) differs from MKMapView.centerCoordinate, but did figure out why .centerCoordinate was off. Part of the map was under the status bar and I ruled the center based on the visible part and overlaying images centered on the visible part, but the map...
Assume line1 and line2 have some value. Create a new array with their points and use the MKPolyline constructor to create a new one. //MKPolyline *line1, *line2; MKMapPoint mapPoints[line1.pointCount + line2.pointCount]; for(NSUInteger i = 0; i < line1.pointCount + line2.pointCount; i++) { mapPoints[i] = (i < line1.pointCount) ? line1.points[i] :...
objective-c,ios8,mapkit,mkmapitem,mkplacemark
MKPlacemark is a subclass of CLPlacemark. CLPlacemark has convenient properties defined for each address element so you don't have to access the dictionary directly by key names. (If you must access the dictionary directly, try using the pre-defined ABPerson Address Property key name constants documented here.) Using the convenient property...