2016-10-04 179 views
-3

我想编写一个应用程序,用户可以通过按下地图在地图上放置图钉。引脚掉线后,我想将引脚保存到数据库中。我不在乎哪一个可能与RealmCoreData如何在地图视图上放置注释并保存销

+0

我认为这是一个完美的教程为你https://www.raywenderlich.com/112544/realm-tutorial-getting-started。在那里你用Realm创建一个基于地图的应用程序作为数据存储 – ronatory

+0

本教程似乎完美谢谢你。我现在就试试 –

回答

0

RTFM

不能真正帮助你无需任何代码或任何问题。

一些链接,可以是有益的: 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

回来你试一下后;)

编辑:

您已定义viewDidLoad方法内手势识别,把它直接在你的控制器中,而应该删除一些错误:

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. 
    } 
} 
+0

我现在在UILongPressGestureRecognisezer * lpgr行中的表达式列表中获得Error expected表达式,并在行中出现预期的错误声明 - (void)handleLongPress:...我真的不知道是什么我的代码错误 –

+0

有一个等号丢失 –

相关问题