I want to code an APP where the User can drop a pin on the map by pressing on the map. After the pin is dropped, I want to save the pin into an database. I don't care in which one maybe with Realm
or CoreData
.
Asked
Active
Viewed 746 times
-3

KSigWyatt
- 1,368
- 1
- 16
- 33

Konrad Löchner
- 49
- 5
-
I think this is a perfect tutorial for you https://www.raywenderlich.com/112544/realm-tutorial-getting-started. There you create a map-based app with Realm as the data storage – ronatory Oct 04 '16 at 14:41
-
the tutorial seems perfekt thank you. I will try this now – Konrad Löchner Oct 04 '16 at 16:56
1 Answers
0
RTFM
Can't really help you without any code, or any problem.
some links that can be helpfull : https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreData/index.html https://developer.apple.com/reference/corelocation https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/LocationAwarenessPG/Introduction/Introduction.html#//apple_ref/doc/uid/TP40009497
come back after you try something ;)
EDIT:
You defined a gesture recognizer inside your viewDidLoad
method, put it directly in your controller instead, that should remove some errors :
import UIKit
import MapKit
class ViewController: UIViewController {
@IBOutlet var mapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
// Create a gesture recognizer for long presses (for example in viewDidLoad)
UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
lpgr.minimumPressDuration = 0.5; //user needs to press for half a second.
[self.mapView addGestureRecognizer:lpgr];
}
- (void)handleLongPress:(UIGestureRecognizer *)gestureRecognizer {
if (gestureRecognizer.state != UIGestureRecognizerStateBegan) {
return;
}
CGPoint touchPoint = [gestureRecognizer locationInView:self.mapView];
CLLocationCoordinate2D touchMapCoordinate = [self.mapView convertPoint:touchPoint toCoordinateFromView:self.mapView];
MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
point.coordinate = touchMapCoordinate;
for (id annotation in self.mapView.annotations) {
[self.mapView removeAnnotation:annotation];
}
[self.mapView addAnnotation:point];
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

Damien
- 3,322
- 3
- 19
- 29
-
I now get the Error expected expression in list of expressions in the line UILongPressGestureRecognisezer *lpgr... and an error expected declaration in the line - (void)handleLongPress:...I don't really know whats wrong with my code – Konrad Löchner Oct 05 '16 at 18:52
-