pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<small id='U6CKc'></small><noframes id='U6CKc'>

<legend id='U6CKc'><style id='U6CKc'><dir id='U6CKc'><q id='U6CKc'></q></dir></style></legend>

    <bdo id='U6CKc'></bdo><ul id='U6CKc'></ul>

      1. <tfoot id='U6CKc'></tfoot>
      2. <i id='U6CKc'><tr id='U6CKc'><dt id='U6CKc'><q id='U6CKc'><span id='U6CKc'><b id='U6CKc'><form id='U6CKc'><ins id='U6CKc'></ins><ul id='U6CKc'></ul><sub id='U6CKc'></sub></form><legend id='U6CKc'></legend><bdo id='U6CKc'><pre id='U6CKc'><center id='U6CKc'></center></pre></bdo></b><th id='U6CKc'></th></span></q></dt></tr></i><div class="siikumi" id='U6CKc'><tfoot id='U6CKc'></tfoot><dl id='U6CKc'><fieldset id='U6CKc'></fieldset></dl></div>

        Swift:用戶位置附近的地理圍欄/地理位置

        Swift: Geofencing / geolocations near user location(Swift:用戶位置附近的地理圍欄/地理位置)

        <i id='V34Tb'><tr id='V34Tb'><dt id='V34Tb'><q id='V34Tb'><span id='V34Tb'><b id='V34Tb'><form id='V34Tb'><ins id='V34Tb'></ins><ul id='V34Tb'></ul><sub id='V34Tb'></sub></form><legend id='V34Tb'></legend><bdo id='V34Tb'><pre id='V34Tb'><center id='V34Tb'></center></pre></bdo></b><th id='V34Tb'></th></span></q></dt></tr></i><div class="aags0o2" id='V34Tb'><tfoot id='V34Tb'></tfoot><dl id='V34Tb'><fieldset id='V34Tb'></fieldset></dl></div>
        • <bdo id='V34Tb'></bdo><ul id='V34Tb'></ul>

          <legend id='V34Tb'><style id='V34Tb'><dir id='V34Tb'><q id='V34Tb'></q></dir></style></legend>

            <tfoot id='V34Tb'></tfoot>

                • <small id='V34Tb'></small><noframes id='V34Tb'>

                    <tbody id='V34Tb'></tbody>
                  本文介紹了Swift:用戶位置附近的地理圍欄/地理位置的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  問題:

                  我試圖讓它一直使用用戶的位置,并不斷檢查它是否在我設置的 CLLocationCoordinate2D 點的 5 英里范圍內.如果是這樣,它會在應用程序打開時發送警報,或者在應用程序關閉時發送通知.

                  I'm trying to make it so that it uses the user's location all the time and constantly checks to see if it is within 5 miles of the CLLocationCoordinate2D points I have set. If so, it sends a alert if the app is open or a notification if the app is closed.

                  有用信息:

                  在我的項目中,我有 4 個 swift 文件:

                  In my project I have 4 swift files:

                  Locations.swift 包含 CLLocationCoordinate2D 點.

                  Utilities.swift 包含一個簡單的警報.

                  Utilities.swift holds a simple alert.

                  UserLocation.swift 檢索并更新用戶的位置

                  UserLocation.swift retrieves and updates the user's location

                  GeoLocationViewController.swift 監控位置

                  注意:

                  某些代碼可能不在正確的位置或不相關,我正在查看另一個項目,試圖從中提取相關代碼以在我的項目中使用.請告訴我你是否發現了錯誤.

                  Some code may not be in the right place or relevant, I was looking at another project trying to extract relevant code from it to use in my project. Please tell me if you do catch a mistake.

                  代碼:

                  Locations.swift:

                  import UIKit
                  import MapKit
                  
                  class Locations: UIViewController {
                  
                      override func viewDidLoad() {
                          super.viewDidLoad()
                          var radius: CLLocationDistance = 5        
                          let arroyo = CLLocationCoordinate2D (latitude: 33.781327997137595, longitude: -116.46394436519012)
                          var arroyoCoord: CLLocationCoordinate2D = arroyo
                  
                          let buddyrogers = CLLocationCoordinate2D (latitude: 33.78051204742721, longitude: -116.46362250010833)
                          var buddyCoord: CLLocationCoordinate2D = buddyrogers
                  
                          let chopsticks = CLLocationCoordinate2D (latitude: 33.815995425565184, longitude: -116.44107442645873)
                          let colorfulfountain = CLLocationCoordinate2D (latitude: 33.80443304398751, longitude: -116.45723923544313)
                          let diamond = CLLocationCoordinate2D (latitude: 33.80216859530781, longitude: -116.45711048941041)
                          let dinahshore = CLLocationCoordinate2D (latitude: 33.806554795852996, longitude: -116.47734507421876)
                          let fountoflife = CLLocationCoordinate2D (latitude: 33.78075282028137, longitude: -116.46407847564086)
                          let fountains = CLLocationCoordinate2D (latitude: 33.780141969313235, longitude: -116.46346156756744)
                          let historicphoto = CLLocationCoordinate2D (latitude: 33.78130570353292, longitude: -116.46389072100982)
                          let holistic = CLLocationCoordinate2D (latitude: 33.781338029257775, longitude: -116.46408249895438)
                          let hollywoodheroes = CLLocationCoordinate2D (latitude: 33.78095792254918, longitude: -116.45820483068849)
                          let indiangathering = CLLocationCoordinate2D (latitude: 33.78136366689296, longitude: -116.46371905963287)
                          let indianwomen = CLLocationCoordinate2D (latitude: 33.78622660767695, longitude: -116.45820483068849)
                          let cathedrals = CLLocationCoordinate2D (latitude: 33.844502990031124, longitude: -116.45834321534426)
                          let firehouse = CLLocationCoordinate2D (latitude: 33.78103817982461, longitude: -116.46700744788512)
                          let perfectunion = CLLocationCoordinate2D (latitude: 33.778193459376865, longitude: -116.45877843062743)
                          let lizards = CLLocationCoordinate2D (latitude: 33.78104263855992, longitude: -116.46340792338714)
                          let cactus = CLLocationCoordinate2D (latitude: 33.782598723009976, longitude: -116.46699671904906)
                          let swisscheese = CLLocationCoordinate2D (latitude: 33.78121541437478, longitude: -116.46472086469993)
                          let newbeginning = CLLocationCoordinate2D (latitude: 33.78049421237406, longitude: -116.46463101069793)
                          let thunderbolt = CLLocationCoordinate2D (latitude: 33.80140187863324, longitude: -116.46646603445436)
                          let tictoc = CLLocationCoordinate2D (latitude: 33.80156235478469, longitude: -116.45524367193605)
                          let wheeloftime = CLLocationCoordinate2D (latitude: 33.815987530910135, longitude: -116.45892863433227)         
                          let artevita = CLLocationCoordinate2D (latitude: 33.7826633, longitude: -116.46041969999999)
                          let coachellaart = CLLocationCoordinate2D (latitude: 33.78012700000001, longitude: -116.46571840000001)
                          let colinfisher = CLLocationCoordinate2D (latitude: 33.7819228, longitude: -116.46002010000001)
                          let garycreative = CLLocationCoordinate2D (latitude: 33.782660, longitude: -116.462141)
                          let lesliejean = CLLocationCoordinate2D (latitude: 33.78404799999999, longitude: -116.4635222)
                          let rebeccafine = CLLocationCoordinate2D (latitude: 33.782487, longitude: -116.460564)        
                          let agnes = CLLocationCoordinate2D (latitude: 33.77571242620008, longitude: -116.46372063254091)
                         let willardprice = CLLocationCoordinate2D (latitude: 33.77489419346815, longitude: -116.46667910908434)
                         let adobe = CLLocationCoordinate2D (latitude: 33.77479870632753, longitude: -116.46673050629039)
                          let valsamuelson = CLLocationCoordinate2D (latitude: 33.76802162366799, longitude: -116.46920998147584)
                          let gallito = CLLocationCoordinate2D (latitude: 33.7794358, longitude: -116.4612692)        
                          let townsquare = CLLocationCoordinate2D (latitude: 33.7810365, longitude: -116.46464559999998)
                          let ocotillo = CLLocationCoordinate2D (latitude: 33.805963, longitude: -116.46349980000002)
                          let century = CLLocationCoordinate2D (latitude: 33.8269913, longitude: -116.4424588)
                          let denniskeat = CLLocationCoordinate2D (latitude: 33.8304982, longitude: -116.45744730000001)
                          let memorial = CLLocationCoordinate2D (latitude: 33.78318512716751, longitude: -116.46681405767208)
                          let patriot = CLLocationCoordinate2D (latitude: 33.8019902897174, longitude: -116.44000872473146)
                          let panorama = CLLocationCoordinate2D (latitude: 33.83861734636407, longitude: -116.46799619895023)
                          let secondst = CLLocationCoordinate2D (latitude: 33.78069442561766, longitude: -116.45910418200071)
                          let dogpark = CLLocationCoordinate2D (latitude: 33.7804269, longitude: -116.46041309999998)
                  
                  
                      }
                  
                  }
                  

                  Utilities.swift:

                  import UIKit
                  import MapKit
                  
                  func showSimpleAlertWithTitle(title: String!, message: String, viewController: UIViewController) {
                      let alert = UIAlertController(title: title, message: message, preferredStyle: .Alert)
                      let action = UIAlertAction(title: "OK", style: .Cancel, handler: nil)
                      alert.addAction(action)
                      viewController.presentViewController(alert, animated: true, completion: nil)
                  }
                  

                  UserLocation.swift:

                  import UIKit
                  import CoreLocation
                  
                  class UserLocation: UIViewController, CLLocationManagerDelegate {
                      var locationManager = CLLocationManager()
                  
                      override func viewDidLoad() {
                          super.viewDidLoad()
                  
                          if (CLLocationManager.locationServicesEnabled()) {
                              locationManager = CLLocationManager()
                              locationManager.delegate = self
                              locationManager.desiredAccuracy = kCLLocationAccuracyBest
                              locationManager.requestAlwaysAuthorization()
                              locationManager.startUpdatingLocation()
                          }
                  
                          locationManager.delegate = self
                          locationManager.requestAlwaysAuthorization()
                  
                      }
                  
                  }
                  

                  GeoLocationViewController.swift:

                  import UIKit
                  import CoreLocation
                  
                  class GeoLocationViewController: UIViewController, CLLocationManagerDelegate {
                  
                      let locationManager = CLLocationManager()
                  
                      override func viewDidLoad() {
                          super.viewDidLoad()
                  
                          locationManager.delegate = self
                          locationManager.requestAlwaysAuthorization()
                  
                          // Do any additional setup after loading the view.
                      }
                  
                      override func didReceiveMemoryWarning() {
                          super.didReceiveMemoryWarning()
                          // Dispose of any resources that can be recreated.
                      }
                  
                      func regionWithGeotification(geotification: Locations) -> CLCircularRegion {
                          // 1
                          let region = CLCircularRegion(center: geotification.coordinate, radius: geotification.radius, identifier: geotification.identifier)
                          // 2
                          region.notifyOnEntry = (geotification.eventType == .OnEntry)
                          region.notifyOnExit = !region.notifyOnEntry
                          return region
                      }
                  
                      func startMonitoringGeotification(geotification: Locations) {
                          // 1
                          if !CLLocationManager.isMonitoringAvailableForClass(CLCircularRegion) {
                              showSimpleAlertWithTitle("Error", message: "Geofencing is not supported on this device!", viewController: self)
                              return
                          }
                          // 2
                          if CLLocationManager.authorizationStatus() != .AuthorizedAlways {
                              showSimpleAlertWithTitle("Warning", message: "Your geotification is saved but will only be activated once you grant permission to access the device location.", viewController: self)
                          }
                          // 3
                          let region = regionWithGeotification(geotification)
                          // 4
                          locationManager.startMonitoringForRegion(region)
                      }
                  
                      func stopMonitoringGeotification(geotification: Locations) {
                          for region in locationManager.monitoredRegions {
                              if let circularRegion = region as? CLCircularRegion {
                                  if circularRegion.identifier ==  geotification.identifier {
                                      locationManager.stopMonitoringForRegion(circularRegion)
                                  }
                              }
                          }
                      }
                  
                      func locationManager(manager: CLLocationManager, monitoringDidFailForRegion region: CLRegion?, withError error: NSError) {
                          print("Monitoring failed for region with identifier: (region!.identifier)")
                      }
                  
                      func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
                          print("Location Manager failed with the following error: (error)")
                      }
                  
                  }
                  

                  推薦答案

                  首先,改回 startMonitoringGeotification()、regionWithGeotification()stopMonitoringGeotification() 來學習一個 Geotification,就像 Ray Wenderlich 教程一樣.確保您已將文件 Geotification.swift 從他的起始代碼添加到您的項目中.

                  First and foremost, change back startMonitoringGeotification(), regionWithGeotification(), and stopMonitoringGeotification() to take in a Geotification like the Ray Wenderlich tutorial. Make sure you have added the file Geotification.swift from his starter code to your project.

                  另外,確保您的 Main.storyboard 啟動您的 ViewController.如果沒有這一步,您的任何代碼都不會運行.

                  Also, make sure your Main.storyboard launches your ViewController. Without this step, none of your code will run.

                  1) 在 Locations.swift 中更簡單地重新定義您的 Locations 類:

                  1) redefine your Locations class more simply in Locations.swift:

                  import UIKit
                  import MapKit
                  
                  class Locations {
                  
                    static let locations:[String:CLLocationCoordinate2D] = [
                      "buddyrogers" : CLLocationCoordinate2D(latitude: 33.815995425565184, longitude: -116.44107442645873),
                      "diamond"     : CLLocationCoordinate2D(latitude: 33.802168595307814, longitude: -116.45711048941041),
                       . 
                       .    // add your locations
                       .
                      ]
                    }
                  }
                  

                  就像@hungry-yeti 建議的那樣

                  like the @hungry-yeti suggested

                  2) 您可以在 GeotificationViewController 類中定義 showSimpleAlertWithTitle().嘗試在您的 ViewDidLoad() 中調用它來測試它.您現在可以刪除 Utilities.swift.

                  2) You can define showSimpleAlertWithTitle() in your GeotificationViewController class. Try calling it in your ViewDidLoad() to test it. You can now delete Utilities.swift.

                  3) 我認為你可以忽略/刪除 UserLocation.swift,這似乎沒有必要

                  3) I think you can ignore/remove UserLocation.swift, this seems unnecessary

                  4) 將此代碼放入GeotificationViewControllerViewDidLoad:

                  4) Put this code inside GeotificationViewController's ViewDidLoad:

                  let radius = CLLocationDistance(8046.72) // 5 miles in meters
                  
                  for location in Locations.locations {
                    let g = Geotification(coordinate: location.1, radius: radius, identifier: location.0, note: "test", eventType: EventType.OnEntry)
                      startMonitoringGeotification(g)
                  }
                  

                  5) 我希望這有助于并簡化您的代碼.派對,如果您有任何問題,請在此處回復.

                  5) I hope this helps and simplifies your code. Party on, reply here if you have any issues.

                  這篇關于Swift:用戶位置附近的地理圍欄/地理位置的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Help calculating X and Y from Latitude and Longitude in iPhone(幫助從 iPhone 中的緯度和經度計算 X 和 Y)
                  Get user#39;s current location using GPS(使用 GPS 獲取用戶的當前位置)
                  IllegalArgumentException thrown by requestLocationUpdate()(requestLocationUpdate() 拋出的 IllegalArgumentException)
                  How reliable is LocationManager#39;s getLastKnownLocation and how often is it updated?(LocationManager 的 getLastKnownLocation 有多可靠,多久更新一次?)
                  CLLocation returning negative speed(CLLocation 返回負速度)
                  How to detect Location Provider ? GPS or Network Provider(如何檢測位置提供者?GPS 或網絡提供商)
                  <legend id='bkzmW'><style id='bkzmW'><dir id='bkzmW'><q id='bkzmW'></q></dir></style></legend>

                  • <tfoot id='bkzmW'></tfoot>
                      <tbody id='bkzmW'></tbody>
                    <i id='bkzmW'><tr id='bkzmW'><dt id='bkzmW'><q id='bkzmW'><span id='bkzmW'><b id='bkzmW'><form id='bkzmW'><ins id='bkzmW'></ins><ul id='bkzmW'></ul><sub id='bkzmW'></sub></form><legend id='bkzmW'></legend><bdo id='bkzmW'><pre id='bkzmW'><center id='bkzmW'></center></pre></bdo></b><th id='bkzmW'></th></span></q></dt></tr></i><div class="2ygeyea" id='bkzmW'><tfoot id='bkzmW'></tfoot><dl id='bkzmW'><fieldset id='bkzmW'></fieldset></dl></div>

                        <small id='bkzmW'></small><noframes id='bkzmW'>

                          <bdo id='bkzmW'></bdo><ul id='bkzmW'></ul>
                          • 主站蜘蛛池模板: 冷却塔减速机器_冷却塔皮带箱维修厂家_凉水塔风机电机更换-广东康明冷却塔厂家 | 广州印刷厂_广州彩印厂-广州艺彩印务有限公司 | 三氯异氰尿酸-二氯-三氯-二氯异氰尿酸钠-优氯净-强氯精-消毒片-济南中北_优氯净厂家 | 企业微信scrm管理系统_客户关系管理平台_私域流量运营工具_CRM、ERP、OA软件-腾辉网络 | sfp光模块,高速万兆光模块工厂-性价比更高的光纤模块制造商-武汉恒泰通 | 锡膏喷印机-全自动涂覆机厂家-全自动点胶机-视觉点胶机-深圳市博明智控科技有限公司 | 茅茅虫AI论文写作助手-免费AIGC论文查重_写毕业论文降重 | 自动钻孔机-全自动数控钻孔机生产厂家-多米(广东)智能装备有限公司 | 包装设计公司,产品包装设计|包装制作,包装盒定制厂家-汇包装【官方网站】 | 固诺家居-全屋定制十大品牌_整体衣柜木门橱柜招商加盟 | 河南不锈钢水箱_地埋水箱_镀锌板水箱_消防水箱厂家-河南联固供水设备有限公司 | 除甲醛公司-甲醛检测-广西雅居环境科技有限公司 | 深圳宣传片制作_产品视频制作_深圳3D动画制作公司_深圳短视频拍摄-深圳市西典映画传媒有限公司 | 立式壁挂广告机厂家-红外电容触摸一体机价格-华邦瀛 | 注塑模具_塑料模具_塑胶模具_范仕达【官网】_东莞模具设计与制造加工厂家 | 大型低温冷却液循环泵-低温水槽冷阱「厂家品牌」京华仪器_京华仪器 | 泉州陶瓷pc砖_园林景观砖厂家_石英砖地铺石价格 _福建暴风石英砖 | DDoS安全防护官网-领先的DDoS安全防护服务商 | 耐破强度测试仪-纸箱破裂强度试验机-济南三泉中石单品站 | 冷水机,风冷冷水机,水冷冷水机,螺杆冷水机专业制造商-上海祝松机械有限公司 | 塑钢课桌椅、学生课桌椅、课桌椅厂家-学仕教育设备首页 | 无锡门窗-系统门窗-阳光房-封阳台-断桥铝门窗厂[窗致美] | 【中联邦】增稠剂_增稠粉_水性增稠剂_涂料增稠剂_工业增稠剂生产厂家 | 温泉机设备|温泉小镇规划设计|碳酸泉设备 - 大连连邦温泉科技 | 工业插头-工业插头插座【厂家】-温州罗曼电气| 众品地板网-地板品牌招商_地板装修设计_地板门户的首选网络媒体。 | 天津蒸汽/热水锅炉-电锅炉安装维修直销厂家-天津鑫淼暖通设备有限公司 | 大数据营销公司_舆情监测软件_上海SEO公司-文军营销官网 | 综合管廊模具_生态,阶梯护坡模具_检查井模具制造-致宏模具厂家 | LINK FASHION 童装·青少年装展 河南卓美创业科技有限公司-河南卓美防雷公司-防雷接地-防雷工程-重庆避雷针-避雷器-防雷检测-避雷带-避雷针-避雷塔、机房防雷、古建筑防雷等-山西防雷公司 | 屏蔽服(500kv-超高压-特高压-电磁)-徐吉电气 | 商用绞肉机-熟肉切片机-冻肉切丁机-猪肉开条机 - 广州市正盈机械设备有限公司 | 全自动真空上料机_粉末真空上料机_气动真空上料机-南京奥威环保科技设备有限公司 | 【MBA备考网】-2024年工商管理硕士MBA院校/报考条件/培训/考试科目/提前面试/考试/学费-MBA备考网 | 东亚液氮罐-液氮生物容器-乐山市东亚机电工贸有限公司 | 喷砂机厂家_自动除锈抛丸机价格-成都泰盛吉自动化喷砂设备 | 深圳律师咨询_深圳律师事务所_华荣【免费在线法律咨询】网 | 电动高尔夫球车|电动观光车|电动巡逻车|电动越野车厂家-绿友机械集团股份有限公司 | 通辽信息港 - 免费发布房产、招聘、求职、二手、商铺等信息 www.tlxxg.net | 字典-新华字典-在线字典查字-字典趣| 智慧农业|农业物联网|现代农业物联网-托普云农物联网官方网站 |