- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
自从更新到 swift 3 之后,我似乎发现了一些错误
// Issue #1
let correctedAddress:String! = self.searchResults![(indexPath as NSIndexPath).row].addingPercentEncoding(withAllowedCharacters: CharacterSet.symbols)
print(correctedAddress)
let url = URL(string: "https://maps.googleapis.com/maps/api/geocode/json?address=\(correctedAddress)&sensor=false")
let task = URLSession.shared.dataTask(with: url!) {
data, response, error in
do {
if data != nil{
let dic = try JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableLeaves) as! NSDictionary
// Issue #2
let results = dic["results"] as! [String: Any]
let geometry = results["geometry"] as! [String: Any]
let location = geometry["location"] as! [String: Any]
let lat = location["lat"] as! Double
let lon = location["lng"] as! Double
self.delegate.locateWithLongitude(lon, andLatitude: lat)
}
}
catch {
print("Error")
}
}
task.resume()
问题#1:例如,correctedAddress 返回值 "%51%75%C3%A9%62%65%63%2C%20%43%61%6E%61%64%61"
。然而,出于某种原因,url 常量返回 nil 并导致崩溃。
我不明白为什么它返回零。我可以将 url 中的 correctedAddress
替换为值 %51%75%C3%A9%62%65%63%2C%20%43%61%6E%61%64%61
所以完整的 url 是
let url = NSURL(string: "https://maps.googleapis.com/maps/api/geocode/json?address=%51%75%C3%A9%62%65%63%2C %20%43%61%6E%61%64%61&sensor=false")
并且工作正常。
问题#2:它在 let results
处崩溃,我返回错误 Could not cast value of type '__NSArrayI' (0x108bb0c08) to 'NSDictionary' (0x108bb1108).
最佳答案
针对您的问题 #2 尝试以下代码
let results = dic["results"] as! NSArray
for result in results {
let strObj = result as! NSDictionary
let geometry = strObj["geometry"] as! NSDictionary
let location = geometry["location"] as! NSDictionary
let lat = location["lat"] as! NSNumber
let lon = location["lng"] as! NSNumber
}
对于问题#1,尝试下面的代码
let valueAtIndex = self.searchResults![(indexPath as NSIndexPath).row].addingPercentEncoding(withAllowedCharacters: CharacterSet.symbols)
guard let correctedAddress = valueAtIndex else { return }
let adrString:String = "https://maps.googleapis.com/maps/api/geocode/json?address=\(correctedAddress)&sensor=false"
let url:URL = URL(string: adrString)!
关于ios - GooglePlaces API Swift 3 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39995402/
我正在尝试构建一个几年前运行良好的应用程序,但现在出现错误,因为找不到 GooglePlaces.h。 如果没有的话,我会得到一些未声明的标识符,例如[突出显示的 enumerateAttribute
为什么我会出错?在为 google places 安装包时我尝试了 pip、easy_install 和 myenv 但无法安装 这是错误 找不到满足 googleplaces 要求的版本(来自版本:
我在我的 Android 应用程序中使用了 googlePlaces 和 google Map API,一切正常。当我启用 Proguard 时,Google Map 工作正常但 Google Pla
我正在关注 this教程,但是当我运行时 pod install 在第 2 步第 6 部分我得到错误 [!] Unable to find a specification for `GooglePla
GooglePlaces.placeDetails api 在解析后给出了错误的结果。 Lat long 返回相同但实际上如果我们在浏览器上点击 API 但在解析后出现错误则不会返回。 GoogleP
我正在尝试在我的应用程序中使用 GooglePlacesAutocomplete。我通过 CocoaPods 安装,我的应用程序的通用压缩和安装大小来自: 46.1 MB 和 70.8 MB 到: 1
在我的 iPhone 应用程序中,我想显示给定纬度和经度最近的商店。 我使用 googlePlaces api 将附近的商店获取到给定的位置坐标。 但我想获取有关商店的其他信息以及每个商店的营业时间和
自从更新到 swift 3 之后,我似乎发现了一些错误 // Issue #1 let correctedAddress:String! = self.searchRe
使用带有搜索栏的标准自动完成代码: placesClient.autocompleteQuery(searchBar.textField.text!, bounds: nil, filter: fil
我一直遇到一个问题,我尝试发送一个获取请求,如果结果中有下一页标记,它将获取该链接并递归地执行另一个请求,直到结果中没有下一页标记。第一个请求工作正常但是当响应中有下一页 token 并且它尝试执行新
总体而言,我对这个模块和 Python 完全陌生,但想在业余时间开始一些有趣的项目。我有一个关于 Python 的 GooglePlaces 模块的具体问题 - 如何仅通过知道其地点 ID 来检索地点
我有一个使用 GoogleMaps 和 GooglePlaces pod 的 objective-c 应用程序,版本 2.7.0 到现在为止。由于最近的弃用,Google 要求将两者升级到 v3.0.
所以 - 经过大量的游戏 - 我找到了一种让它发挥作用的方法,但我有一个东西我不知道如何绕过(并且让我发疯......)。 我有一个 watch 应用程序,需要来自 GooglePlaces 的数据(
我有一个使用 GooglePlaces API 的 iOS 应用程序。我使用“添加结果 Controller ”技术来实现搜索栏,而不是像这样将搜索器分配给 navigationItem.titlev
存档时遇到问题 - 我收到一条构建系统信息错误,内容为 Multiple commands produce '.../Library/Developer/Xcode/DerivedData/.../B
存档时遇到问题 - 我收到一条构建系统信息错误,内容为 Multiple commands produce '.../Library/Developer/Xcode/DerivedData/.../B
我是一名优秀的程序员,十分优秀!