【问题标题】:iOS 7 Parse GeolocationiOS 7 解析地理定位
【发布时间】:2014-04-07 08:18:07
【问题描述】:

我正在开发适用于 iOS 7 的应用程序,我需要找到用户的位置,然后查看其他用户也在同一位置。我需要它在用户打开应用程序后立即更新,并且每隔一段时间更新一次,并将用户显示在同一位置。我已经查看了可用的示例,但是使用 Parse 似乎还不够。任何人都可以就如何做这件事给我任何帮助,或者如果有人知道一些类似于我正在尝试做的例子,我将不胜感激。提前致谢!

【问题讨论】:

    标签: ios parse-platform geolocation reverse-geocoding


    【解决方案1】:

    你需要分解你的问题并解决各个部分 -

    1. 在应用打开时定期获取用户的位置 Location and Maps programming guide 是一个很好的起点。您可以使用 CLLocationManager 获取您的初始位置,并且您可以注册重要的位置更改事件以定期获取更新,即使您的应用程序没有运行。 Apple 有示例代码,还有很多其他示例 - 只需使用“核心位置示例”进行搜索
    2. 将用户的位置存储在 Parse 数据库中 Parse.com 上的示例和文档展示了如何执行此操作。您还可以提供 Web 服务,允许您的应用在数据库中查询同一位置的其他用户
    3. 在您的应用未运行时识别同一位置的其他用户 您可以使用 Parse 后台作业来搜索您的数据库、匹配用户位置并向您的用户发送推送通知。 Parse.com 上的示例再次展示了如何设置后台作业和推送通知

    【讨论】:

    • 谢谢!我能够找到 Parse 后台作业的文档。我会试试看。
    【解决方案2】:

    这可能有助于获取您当前的位置然后保存以进行解析,这只是查询解析以提取数据的问题

    func locationManager(manager: CLLocationManager!, didUpdateLocations  
    locations: [AnyObject]!) {
    
        var userLocation : CLLocation = locations[0] as! CLLocation
    
        var latitude = userLocation.coordinate.latitude
        var longitude = userLocation.coordinate.longitude
    
        var latDelta : CLLocationDegrees = 0.01
        var lonDelta : CLLocationDegrees = 0.01
    
        var span : MKCoordinateSpan = MKCoordinateSpanMake(latDelta,  
        lonDelta)
    
        var location : CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude)
        var region : MKCoordinateRegion = MKCoordinateRegionMake(location, span)
    
        self.mapView.setRegion(region, animated: true)
    
        let testObject = PFObject(className: "User")
    
        let currentPoints = PFGeoPoint(latitude: latitude, longitude: longitude)
    
        testObject.setValue(currentPoints, forKey: "currentLocation")
    
        testObject.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in
    
            if (success) {
    
                dispatch_async(dispatch_get_main_queue()) {
    
                    println("added to parse")
                }
    
    
            } else {
    
                println(error)
    
            }
    
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2015-05-10
      • 1970-01-01
      • 2022-01-26
      • 2013-10-24
      • 1970-01-01
      • 1970-01-01
      • 2021-12-29
      • 2016-10-26
      • 1970-01-01
      相关资源
      最近更新 更多