FAQ Database Discussion Community


Swift - How to ask UIGestureRecognizer function to return value

swift,mkmapview,uigesturerecognizer
I would like to ask function annotation to return the coordinate (CLLocationCoordinate2D) for other function to use, here's my partial code: // ULMap is MapView. override func viewDidLoad() { var longPressGR = UILongPressGestureRecognizer(target: self, action: "annotation:") longPressGR.minimumPressDuration = 1 UImap.addGestureRecognizer(longPressGR) } func annotation(gesture: UIGestureRecognizer){ //Coordinate var touchPoint = gesture.locationInView(self.UImap) var...

MKMapView MKCircle renders a circle with too big radius

ios,swift,geolocation,mkmapview
I'm facing with a strange behaviour of MKCircle appearance. Basically I'm trying to draw a circle with a radius of 8500 km with an arbitrary center. Here is my code: private func addCircle() { mapView.removeOverlays(mapView.overlays) let circle = MKCircle(centerCoordinate: mapCenter, radius: 8500000.0) mapView.addOverlay(circle) } I also have a custom double...

Mkpolyline is not being drawn

ios,iphone,xcode,mkmapview,mkpolyline
The route is clearly being made but the polyline is not drawn. I am able to find the total distance, and have verified that the coordinates we are using are not (0,0). Is there something wrong with the delegate, since it seems that both the addOverlay and addAnnotation (called in...

Hidden MKMapView is somehow receiving touches when scrolling UITableview that is on top

ios,objective-c,uitableview,mkmapview
I have a UIViewController that uses a segmentedControl to switch between a MKMapView and a UITableView controller. The map shows some locations, then switching to list will show those in list form. When toggling the segmentedControl it will show the corresponding view and hide the other. The extremely strange issue...

How to draw UIBezierPath overlay on MKMapView?

ios,mkmapview,mapkit,mkoverlay
I try to subclass from MKOverlayPathRenderer and implement -createPath - (void)createPath { MKPolyline *line = (id)self.overlay; MKMapPoint *points = line.points; NSUInteger pointCount = line.pointCount; CGMutablePathRef path = CGPathCreateMutable(); CGPathMoveToPoint(path, NULL, points[0].x, points[0].y); for (int i = 1; i < pointCount; i++) { CGPathAddLineToPoint(path, NULL, points[i].x, points[i].y); } [self setPath:path]; }...

Check if MKPolyline overlay already exists

ios,mkmapview,mkoverlay,mkpolyline
How can I check if a polyline has already been added to the map? I've tried the following code, but it doesnt seem to work for (MKPolyline *feature1 in self.mapView.overlays) { NSLog(@"feature1.title: %@", feature1.title); NSLog(@"Polu.title: %@", polu.title); if (![feature1.title isEqualToString:polu.title]) { NSLog(@"NOT"); [self.mapView addOverlay:polu]; } else { NSLog(@"Already added"); }...

Understand the response of Open street map query response

ios,iphone,mkmapview,mapkit,openstreetmap
I am trying to get the speed limit of the surrounding locations of a specific coordinate. OSM Query: www.overpass-api.de/api/xapi?*[maxspeed=*][bbox=5.6283473,50.5348043,5.6285261,50.534884] Response: <?xml version="1.0" encoding="UTF-8"?> <osm version="0.6" generator="Overpass API"> <note>The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.</note> <meta osm_base="2015-06-09T07:04:02Z"/> <node id="21265775" lat="50.5350159" lon="5.6293520"/> <node...

Swift compiler error on mapView declaration

ios,swift,mkmapview,mkannotationview,mkmapviewdelegate
I upgraded to a newer Swift compiler and ran into this compiler error I can’t figure out how to resolve. I have a bunch of mapView functions declared from the MKMapViewDelegate. They all seem to match up except this one which throws this error: ViewController.swift:137:10: Objective-C method 'mapView:viewForAnnotation:' provided by...

iOS: Button backgroundImage not changing in Annotation Callout View

ios,uibutton,mkmapview,calloutview
I have a MKMapView with a number of annotations representing stores. When the user taps on an annotation I present a custom annotation view. This view contains a favourite button, that adds the store to the user's favourites. If the user presses this button it changes its backgroundImage property to...

iOS 8 Weird animation on MKMapView callout when using leftCalloutAccessoryView to display lengthy content

ios,ios8,mkmapview,callout
I have a weird issue with MKMapView's callout view. I am using leftCalloutAccessoryView to set up a view that holds an image and a couple of labels as shown in the picture below. Whenever I tap the annotation, the animation that normally shows the callout appears and then the my...

Issue persisting MKPolygon points using Parse framework

swift,parse.com,mkmapview,pfquery,mkpolygon
I have the following method that saves points to Parse.com using the PFGeoPoint object: I capture them using: func convertPoint(touch: UITouch) { let location = touch.locationInView(self.mapView) as CGPoint let coordinate: CLLocationCoordinate2D = self.mapView.convertPoint(location, toCoordinateFromView: self.mapView) self.coordinates.addObject(NSValue(MKCoordinate: coordinate)) } Then I use the following to add them to Parse: func addPolygonToMap()...

How to add Coordinates to CLLocationCoordinate2D from Dynamic NSMutableArray?

ios,objective-c,annotations,nsmutablearray,mkmapview
I have a MapView in which I would like to add annotations and a route from defined coordinates that I add from a Textfield and store in an NSMutableArray. Now I'm able to show the route from multiple coordinates but only when I insert them in my code as follow...

How to add overlay path in MKMapView swift

ios,swift,mkmapview,mkoverlay,coordinate
I want to add a overlay path among multiple coordinates in mapview. I tried like below code, but it shows a error of "cannot invoke 'map' with an argument list of type ((CLLocation) -> CLLocationCoordinate2D)". Please let me know how can i fix this ? My ViewController.swift file import UIKit...

CLLocationManager fatal error: unexpectedly found nil while unwrapping an Optional value Swift

ios,swift,mkmapview,cllocationmanager
I have a problem because my app crash when i try to get position user and have permission in my .plist this my code. import UIKit import MapKit import CoreLocation class mapClass : UIViewController,MKMapViewDelegate,CLLocationManagerDelegate{ var location4 = CLLocation() var lm = CLLocationManager () @IBOutlet var propMapa: MKMapView! lm.delegate=self lm.desiredAccuracy =...

Unable to get custom MKAnnotationView callout to appear

objective-c,osx,mkmapview,mapkit,mkannotation
I'm building an OSX application that uses Mapkit, and I'm trying to get a callout to appear when I click on an MKAnnotationView on my map. To do this I'm implementing the MKMapViewDelegate, and the following function : - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation { if ([annotation isKindOfClass:[LocationPin class]]) { LocationPin...

Callout action from Annotations in Map view

ios,xcode,swift,mkmapview,mkannotation
I have an array of latitudes and longitudes along with other stuffs and I want to create annotations in Map view. I’m using MapKit. When ever the user clicks the annotation callout I’m going to present another controller. I’m not able to find the index of the array element that...

IOS/Objective C/MKMapViewDelegate: Get annotationView to show accessory arrow

ios,mkmapview,mkannotationview
I am trying to use some delegate methods in MKMapViewDelegate. Specifically, I want to give the pop out an accessory arrow so that when user touches it, it launches native map application (for full blown mapping functions.) I think I understand correctly that once the VC is set up as...

MKMapView or CLLocationManger - to determine user's current location

ios,cocoa-touch,mkmapview,mapkit,cllocationmanager
There are two classes that help regarding map plotting and determining user location - MKMapView and CLLocationManager. MKMapView has a delegate “didUpdateUserLocation” that tells the user’s current location. At the same time, CLLocationManger has a delegate “didUpdateToLocation” and it also does the same thing. My question is when to use...

MKAnnotation setImage works on iPhone, but not iPad/iPhone 6+

ios,ipad,mkmapview,mkannotation,mkannotationview
I am trying to set a custom image for an MKPointAnnotation in my MKMapView. The images are set correctly on all iPhones except for 6+: But on iPhone 6+ and iPad, the annotation has the default pin instead of my picture: Below is the code that sets the image of...

MKAnnotation Pin won't drag, even though set as draggable

ios,swift,mkmapview,mkpinannotationview,mkmapviewdelegate
I have been trying to put a draggable annotation on a mapview for ages. (I'm using the default pin, not my own) So far I can only display it at set coordinates (not much of an achievement, really) and I need to get the annotation first of all to react...

MKAnnotationView image changing issue

ios,mkmapview,mkannotation,mkannotationview
I've got an MKMapView loaded with plenty of custom annotation (800 circa). When I drag on the map and I return to an annotation, it's image has changed with another one. For me it's seems like a cache issue. Pin before dragging Pin after dragging SuperClass header #import <Foundation/Foundation.h> #import...

Setting Parse PFGeopoints on a map only viewable for current user

parse.com,mkmapview,cllocationmanager
I have an array of PFGeopoints which I query from parses back end database, and I then annotate them points onto a MapView. I now a feature in my app where you can turn yourself off so nobody can see where you are, but the current user can still see...

Filter array based on coordinate from mapview frame in objective C

ios,objective-c,xcode,annotations,mkmapview
I have hundred's of map annotation. Annotation are from array of dictionary with lat and long val same data shown in table view. Table view and map view are same view based on screenheight/2. What I need for example in my array have 100 lat and long value table view...

MKMapView MKPointAnnotation tap event not called

ios,swift,mkmapview,mkannotationview,mkpointannotation
I am using a MKMapView (delegate is set correctly) with a MKPointAnnotation. The annotations are generated in this method called on a background thread. func updateMapAnnotations() { for var i = 0; i < DataManager.getStationList().count; i++ { var s = DataManager.getStationList()[i] as Station var annotation = MKPointAnnotation() annotation.setCoordinate(CLLocationCoordinate2D(latitude: s.latitude, longitude:...

Recognize current location route type

objective-c,mkmapview,cllocation
I am working on a project where I have to distinguish the mobility type ( car, tramway, bus, train, subway... ) I am currently using a speed system to distinguish most of them using a min and max for each type ( not efficient you will say :) ) But...

Swift cannot assign subtitle in MKAnnotation

ios,swift,mkmapview,mkannotation
I'm attempting to programmatically update the subtitle within MKAnnotation. The following lines of code produce a cannot assign subtitle in annotation error: let annotation: MKAnnotation = mapView.annotations[0] as! MKAnnotation annotation.subtitle = nil Could anyone help lead me in a direction where I can update the subtitle after the MKAnnotation is...

Determine if coordinate is inside region (MKMapView, solve in PHP)

php,mkmapview,latitude-longitude,coordinate-systems
I'm using MKMapView and I send my php program the visible region (center lat, center lon, span lat, span lon). I need to determine if a coordinate is inside that region using php. I'm hoping there's a standard formula somewhere, but I haven't found one. I'll keep trying to come...

Get SW/NE point on MKMapView after rotation

ios,swift,mkmapview
I'm writing an application in Swift, and using Parse as the back-end. In order to setup a query to Parse, I want to get the southwest-most point and northeast-most point displayed on the current MKMapView. I currently get these values as displayed here: //___ To calculate the search bounds, first...

iOS Custom annotations for MKMapView

ios,mkmapview,mapkit,mkannotation,mkannotationview
First of all I'm using kingpin in order to display an array of annotations. Everything works just as expected. My question is: How can I create a custom view for an annotation? And I'm not referring to replacing the image of MKPinAnnotationView. if (annotationView == nil) { annotationView = [[MKPinAnnotationView...

Create multiple MKMapView snapshots serially

ios,mkmapview,mkmapsnapshotter
I wrote and use THIS CLASS to create small snapshot images of MKMapView with a custom annotation, and set them inside an UIImageView in a UITableViewCell. I wrote it in such a manner, to invoke and forget, without worrying too much about memory consumption. How it works: I have a...

viewForAnnotation sometimes can't get custom MKAnnotation class and render it properly

swift,mkmapview,mkannotation,mkannotationview
I have different classes (MKAnnotation subclass) that represent map annotations. I load them on the map and it's fine but when I move or zoom map pins starts to loosing their image. When I pan map viewForAnnotation is called but pin that is BluePin class for example not anymore get...

How i can show the location name with Pin Point in MapView

xcode,ios8,mkmapview
I want to show to location name and the pin point in my mapView.I Tried many ways but none of them help me. And I am stuck at this position. i am using this piece of code: -(void)getMe:(id)sender { [self.view endEditing:YES]; NSString *addresss = userText.text; NSString *esc_addr = [addresss stringByAddingPercentEscapesUsingEncoding:...

showAnnotations when rotation changes

ios,swift,mkmapview,mkannotation,orientation-changes
I have a SplitViewController with a mapview on as the detailViewController. I add multiple annotations to the mapview. After adding them I call the showAnnotations:animated: method to zoom in/out the map so that all the annotations are shown in the visible portion of the map. mapView.showAnnotations(mapView.annotations, animated: true) Now I...

Xcode user location no longer working in newer version (Objective-C)

ios,objective-c,xcode,uibutton,mkmapview
I have a button which moves to the user's location. I declare it in ViewControler.h and then added the following code into ViewController.m: - (IBAction)userLocation:(id)sender { [_mapView setCenterCoordinate:_mapView.userLocation.location.coordinate animated:YES]; } This keeps leading me to the (0,0) coordinates. Is there something in the newer Xcode version that I need to...

Show annotation title automatically

swift,mkmapview,mkannotation
I'm trying to display the annotation title automatically instead of displaying it on tap. I used the below code to display annotation and make it center on map. self.ann.setCoordinate(currentLocation2D) self.ann.title = "Title" self.ann.subtitle = "Subtitle" self.mapView.addAnnotation(self.ann); self.span = MKCoordinateSpanMake(0.005, 0.005) self.region = MKCoordinateRegion(center: currentLocation2D, span: self.span) self.mapView.setRegion(self.region, animated: true) I...

How to select map pin when tapping table row that associates with it?

ios,objective-c,parse.com,mkmapview,tableview
Here I have 2 views: WallViewController TableViewController WallViewController contains MKMapView, and TableViewController is a subclass of PFQueryTableViewController displaying rows of content that associate with annotation pin on WallViewController. TableViewController is added as subview in WallViewController, so these 2 views are displayed together. Now when I tap annotation pin on the...

MKPolylineView initWithPolyLine: is deprecated in iOS 7

ios,mkmapview,mapkit,deprecated,mkpolyline
I am getting the following error: initWithPolyline: is deprecated: first deprecated in iOS 7.0 MKPolylineView *lineView = [[MKPolylineView alloc] initWithPolyline:overlay]; What is the replacement method of instead of this ?...

Failed to set maprect to show all annotations

swift,mkmapview,mkannotation,mkmaprect
I have 2 annotations to display on the mapview, but unable to set the maprect to show all of them on screen without requiring users to zoom out. I tried with showAnnotations but no luck. Anyone has been able to do this in Swift and Xcode 6.1.1? Here is my...

Custom one annotation on MKMapView

ios,objective-c,mkmapview
I fill my map with MKPLaceMark, with a specific address, these mark correspond to a meeting. I'm trying to custom one placemark that corresponds to the next meeting. Here is my code: // Function to add all pin corresponding to all meeting. - (void) addAllPins { _myMap.delegate = self; //...

I cannot get my MKRoute to show up on a MapView. I'm very stuck

ios,swift,mkmapview,mkoverlay
I am trying to add an MKOverlay (my MKRoute) to my MapView, but I cannot figure out what I am doing wrong. This is pretty sloppy because I'm experimenting with it before I implement it in my app. Here's the code: import UIKit import MapKit import CoreLocation class ViewController: UIViewController,...

Adding a custom annotation to a MKMapview

ios,mkmapview,mapkit,mapkitannotation
I am trying to add annotations to a MKMapView I have created a class CustomMapPin which conforms to the MKAnnotation protocol #import <Foundation/Foundation.h> #import <MapKit/MapKit.h> @interface CustomMapPin : NSObject <MKAnnotation> { CLLocationCoordinate2D coordinate; NSString *title; NSString *subtitle; } @property(nonatomic, assign) CLLocationCoordinate2D coordinate; @property(nonatomic, copy) NSString *title; @property(nonatomic, copy) NSString *subtitle;...

Adding a pin annotation to a map view on a long press in swift

ios,swift,annotations,maps,mkmapview
I'm trying to make an iPhone app which requires users to be able to long press on a place on a map view to drop a pin there. Does anybody know how this is done? The behaviour is observable in apple maps when you long press on the screen. It...

delay showing UIMapView until map fully loaded in Swift

swift,ios8,mkmapview
On my story board, I have set up a timer (which updates every 0.01 seconds) and a UIMapView which displays the user's location when the view controller is loaded. However, when this screen loads, the timer lags for a bit until the map is fully loaded. I assume this is...

iOS MKMapView viewForOverlay not called

ios,mkmapview
I'm losing my mind here. Why is this not working?? update_map method gets called but viewForOverlay doesn't. - (void)viewDidLoad { [super viewDidLoad]; if(mapView2 != nil) { [self update_map]; } - (void)update_map { CLLocationDistance fenceDistance = 100000; MKCircle *circle = [MKCircle circleWithCenterCoordinate:newCoord radius:fenceDistance]; [mapView2 addOverlay:circle]; } - (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay...

custom annotationView label overlap (causing MKMapView memory leak)

swift,mkmapview,mkannotation,mkannotationview
I am building an app using mkmapview. I am using custom annotation views to display avatars and corresponding labels. Everything works fine: Each avatar and the corresponding label are displayed properly. I can navigate in the map. But when I zoom out at the maximum, and there are let's say...

Xcode UIScrollView zoom same as MKMapView zoom (no effect on subview)

ios,objective-c,uiscrollview,mkmapview,zoom
I want to add zoom effect on my UIScrollView . That i have achieved it with UIScrollView delegate methods. (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView. Now i want to add the effect that MKMapView is having in it, that if we zoom-in or zoom-out the MKMapView place marker of the map remains at...

How to add directions among two custom locations in Mapview for IOS 7 (objective c)

objective-c,ios7,ios8,mkmapview
I have to add directions among two custom locations in IOS 7. Any one tell me please. Thanks. ...

MKMapView not staying rotated

ios,iphone,swift,mkmapview
Easy to reproduce: - create a new project - put an MKMapView on the screen - try to rotate it with 2 fingers It rotates a little and stops, and when you release the fingers, it goes back to the original position. How do I make it stay rotated? And...

mapView:didSelectAnnotationView gets fired only once

ios,mkmapview,mkannotationview
I have a MKMapView, I display one MKAnnotaionView on top of it. My problem is when I click on the AnnotationView the first time, mapView:didSelectAnnotationView gets called, but if I click on it again nothing happens. Why is this happening?