- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
你好,在我当前的项目中我有:
class SecondController: UIViewController, CLLocationManagerDelegate {
var allPoly : [GMSPolyline] = []
private let rootKey = "rootKey"
func applicationWillResignActive(notification: NSNotification)
{
let filePath = self.dataFilePath()
let savedPolys = SavedPolys()
let array = self.allPoly as NSArray
savedPolys.alPoly = array as? [GMSPolyline]
let data = NSMutableData()
let archiver = NSKeyedArchiver(forWritingWith: data)
archiver.encode(savedPolys, forKey: rootKey)
archiver.finishEncoding()
data.write(toFile: filePath, atomically: true)
}
func dataFilePath() -> String
{
let paths = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)
let documentsDirectory = paths[0] as NSString
return documentsDirectory.appendingPathComponent("data.archive") as String
}
func buttonPressed()
{
//adds a polyline to allPoly!
}
}
以及另一个类:
import Foundation
import GoogleMaps
class SavedPolys: NSObject, NSCoding, NSCopying
{
var alPoly: [GMSPolyline]?
let polyKey = "polyKey"
override init()
{
}
required init?(coder aDecoder: NSCoder)
{
alPoly = aDecoder.decodeObject(forKey: polyKey) as? [GMSPolyline]
}
func encode(with aCoder: NSCoder) {
if let savePoly = alPoly
{
aCoder.encode(savePoly, forKey: polyKey)
}
}
func copy(with zone: NSZone? = nil) -> Any {
let copy = SavedPolys()
if let polysToCopy = alPoly
{
var newPolys = Array<GMSPolyline>()
for poly in polysToCopy
{
newPolys.append(poly)
}
copy.alPoly = newPolys
}
return copy
}
}
我试图做到这一点,如果用户将多边形添加到 allPoly 数组,然后关闭他们的应用程序,则该数组将被保存,然后在他们打开应用程序时重新加载。我已经尝试按照我类(class)教科书中的一章(这是所有这些的来源)进行操作,但是当前代码在这一行给我一个错误:“archiver.encode(savedPolys, forKey: rootKey)”。它说“无法识别的选择器发送到实例”。谁能帮我?有更简单的方法吗?谢谢!
最佳答案
您正在复制的代码有点旧,并且 API 发生了变化,这就是它抛出错误的原因。下面是修改后的代码:
swift 2.3
class SavedPolys : NSObject, NSCoding, NSCopying
{
var alPoly: [GMSPolyline]?
let polyKey = "polyKey"
override init()
{
}
required init?(coder aDecoder: NSCoder)
{
alPoly = aDecoder.decodeObjectForKey(polyKey) as? [GMSPolyline]
}
func encodeWithCoder(aCoder: NSCoder)
{
if let savePoly = alPoly
{
aCoder.encodeObject(savePoly, forKey: polyKey)
}
}
func copyWithZone(zone: NSZone) -> AnyObject
{
let copy = SavedPolys()
if let polysToCopy = alPoly
{
var newPolys = Array<GMSPolyline>()
for poly in polysToCopy
{
newPolys.append(poly)
}
copy.alPoly = newPolys
}
return copy
}
}
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var allPoly : [GMSPolyline] = []
private let rootKey = "rootKey"
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
let filePath = self.dataFilePath()
let savedPolys = SavedPolys()
let array = self.allPoly as NSArray
savedPolys.alPoly = array as? [GMSPolyline]
let data = NSMutableData()
let archiver = NSKeyedArchiver(forWritingWithMutableData: data)
archiver.encodeObject(savedPolys, forKey: rootKey)
archiver.finishEncoding()
data.writeToURL(NSURL(fileURLWithPath: filePath), atomically: true)
return true
}
func dataFilePath() -> String
{
let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
let documentsDirectory = paths[0] as NSString
return documentsDirectory.stringByAppendingPathComponent("data.archive")
}
}
swift 3.0
class SavedPolys : NSObject, NSCoding, NSCopying
{
var alPoly: [GMSPolyline]?
let polyKey = "polyKey"
override init()
{
}
required init?(coder aDecoder: NSCoder)
{
alPoly = aDecoder.decodeObject(forKey: polyKey) as? [GMSPolyline]
}
func encode(with aCoder: NSCoder)
{
if let savePoly = alPoly
{
aCoder.encode(savePoly, forKey: polyKey)
}
}
func copy(with zone: NSZone? = nil) -> Any
{
let copy = SavedPolys()
if let polysToCopy = alPoly
{
var newPolys = Array<GMSPolyline>()
for poly in polysToCopy
{
newPolys.append(poly)
}
copy.alPoly = newPolys
}
return copy
}
}
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var allPoly : [GMSPolyline] = []
private let rootKey = "rootKey"
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let filePath = self.dataFilePath()
let savedPolys = SavedPolys()
let array = self.allPoly as NSArray
savedPolys.alPoly = array as? [GMSPolyline]
let data = NSMutableData()
let archiver = NSKeyedArchiver(forWritingWith: data)
archiver.encode(savedPolys, forKey: rootKey)
archiver.finishEncoding()
data.write(to: NSURL(fileURLWithPath: filePath) as URL, atomically: true)
return true
}
func dataFilePath() -> String
{
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
let documentsDirectory = paths[0] as NSString
return documentsDirectory.appendingPathComponent("data.archive")
}
}
关于arrays - 如何保存 [GMSPolyline] 以便在用户关闭和打开应用程序时它仍然保留数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40880141/
在允许用户在各种不同类型的 map 上显示复杂位置点列表(我们称之为轨迹)的 GPS 应用中,每个轨迹可以包含 2k 到 10k 个位置点。当轨迹在非 Google map 类型上呈现时,它们会被大量
我看到 GMSPolyline 协议(protocol)已经为其描边颜色定义了一个 color 属性,但是有没有办法对其多边形内部进行阴影处理(理想情况下具有透明度) ?我正在寻找相当于 MKPoly
将折线添加到 map 后,有时会出现连线现象。就像线条发生了变形和旋转一样。缩放 map 时,线条在晃动。 我录制了一段视频: https://drive.google.com/file/d/14mY
我已经在使用GMSGeometryContainsLocation的方法了为了确定坐标(来自点击用户)是否在 GMSPolygon 内,但我不能让它适用于 GMSPolyline。 -(void) d
我正在使用适用于 ios 的 google map sdk 来提供当前用户位置和结束位置之间的方向。到目前为止,我已经使用下面的代码在当前用户位置和结束位置之间绘制了一条 GMSPolyline,并且
,在我们的应用程序中,用户可以在 map 上创建 GMS- 要素。然后这些功能是可编辑的,编辑过程从点击开始。在某些情况下,如果应用于折线的样式是 1 点或 2 点线,则用户很难点击它们。我对此进行了
你好,在我当前的项目中我有: class SecondController: UIViewController, CLLocationManagerDelegate { var allPoly : [
我需要在某些情况下将 GMSPolyline 从一个位置移动到另一个位置。这是场景: 用户打开 GMSMapView 并创建 GMSPolyline 要素。 然后用户改变 map 位置 用户点击一个按
我正在使用 GoogleMap-IOS-1.8.1 SDK 来显示 map 。我必须在 map 上绘制一条 GMSPolyline。在特定事件之后,我必须删除除标记之外的所有 GMSPolyline
我正在开发一个应用,它使用 NextBus API 和 Google map 显示公交路线。但是,我遇到了 CPU 使用问题,我认为这是由 map 上的 GMSPolylines 数量引起的。路线由一
我正在开发一个导航应用程序并跟踪用户在已绘制的 GMSPolyline 上的当前移动。当用户直行时效果很好。现在,假设 GMSPolyline 上有右转/左转或掉头,现在根据我的 GPS 位置,我在转
我正在使用谷歌地图 iOS sdk。我使用以下代码在我的谷歌地图上添加了折线。但现在我想在这一行的末尾添加箭头。如何解决这个问题? GMSMutablePath *path = [GMSMutable
我使用的是谷歌地图 SDK,我必须在用户移动时绘制多段线,目前它只为标记设置动画,在图钉移动到特定位置之前绘制路径。我必须同时绘制路径和移动图钉。 查看此视频:https://www.dropbox.
我正在努力检测在我的 Google map 上绘制的 GMSPolyline 上的点击,它适用于 GMSpolygones,但同样的方法似乎不适用于折线。我目前适用于多边形的方法是: if (GMSG
我在互联网上找不到任何 Google Maps SDK 最佳实践,所以我在这里问。我正在开发一个包含大量 GMSMarkers (200+) 和 GMSPolylines (9000+) 的应用程序。
我对谷歌地图还很陌生,这个问题已经困扰我好几天了。 我基本上有一组坐标点,我将其转换为 GMSPath 对象。然后使用此路径对象在我的 GMSMapView 上绘制和呈现 GMSPolyline。这绝
我正在使用谷歌距离 API ["https://maps.googleapis.com/maps/api/directions/json?origin= "+start.latitude + ","+
我在 iOS 7.1 中使用 google map sdk 如何为 GMSPolyline 设置颜色,默认为黑色。我尝试使用 setStrokeColor 和 setSpans: setStrokeC
根据入门指南添加了所有内容。加载 map ,我可以毫无问题地将 GMSMarker 添加到 map 中。我有一个绘制多边形的方法,但应用程序每次都会崩溃。 方法: -(void)drawPolygon
我是一名优秀的程序员,十分优秀!