我创建了这个类
import UIKit
import CoreLocation
private let geometryKey = "geometry"
private let locationKey = "location"
private let latitudeKey = "lat"
private let longitudeKey = "lng"
private let nameKey = "name"
private let openingHoursKey = "opening_hours"
private let openNowKey = "open_now"
private let vicinityKey = "vicinity"
private let typesKey = "types"
private let photosKey = "photos"
private let phoneNumberKey = "phoneNumber"
private let ratingKey = "rating"
private let priceLevelKey = "priceLevel"
private let websiteKey = "website"
class QPlace: NSObject {
var location: CLLocationCoordinate2D?
var name: String?
var photos: [QPhoto]?
var vicinity: String?
var isOpen: Bool?
var types: [String]?
var rating: Float?
var priceLevel: Int?
var website: String?
var phoneNumber: String?
init(placeInfo:[String: Any]) {
// coordinates
if let g = placeInfo[geometryKey] as? [String:Any] {
if let l = g[locationKey] as? [String:Double] {
if let lat = l[latitudeKey], let lng = l[longitudeKey] {
location = CLLocationCoordinate2D.init(latitude: lat, longitude: lng)
}
}
}
// name
name = placeInfo[nameKey] as? String
// opening hours
if let oh = placeInfo[openingHoursKey] as? [String:Any] {
if let on = oh[openNowKey] as? Bool {
isOpen = on
}
}
// vicinity
vicinity = placeInfo[vicinityKey] as? String
// types
types = placeInfo[typesKey] as? [String]
// rating
rating = placeInfo[ratingKey] as? Float
//priceLevel
priceLevel = placeInfo[priceLevelKey] as? Int
//website
website = placeInfo[websiteKey] as? String
//phoneNumber
phoneNumber = placeInfo[phoneNumberKey] as? String
// photos
photos = [QPhoto]()
if let ps = placeInfo[photosKey] as? [[String:Any]] {
for p in ps {
photos?.append(QPhoto.init(photoInfo: p))
}
}
}
func getDescription() -> String {
var s : [String] = []
if let types = types {
s.append("\(types.joined(separator: ", "))")
}
if let rating = rating {
s.append("Rating: \(rating)")
}
if let priceLevel = priceLevel {
s.append("Price level: \(priceLevel)")
}
if let isOpen = isOpen {
s.append(isOpen ? "OPEN NOW" : "CLOSED NOW")
}
if let phoneNumber = phoneNumber {
s.append("Phone number:\(phoneNumber)")
}
if let website = website {
s.append("\(website)")
}
if let vicinity = vicinity {
s.append("\(vicinity)")
}
return s.joined(separator: "\n")
}
func getDescriptionMaps() -> String {
var m : [String] = []
if let vicinity = vicinity {
m.append("\(vicinity)")
}
return m.joined(separator: "\n")
}
func heightForComment(_ font: UIFont, width: CGFloat) -> CGFloat {
let desc = getDescription()
let rect = NSString(string: desc).boundingRect(with: CGSize(width: width, height: CGFloat(MAXFLOAT)), options: .usesLineFragmentOrigin, attributes: [NSFontAttributeName: font], context: nil)
return ceil(rect.height)
}
}
在表格的单元格中显示地点详细信息(我正在使用Google地方)。我的问题是网站,价格水平和电话号码不起作用(它没有下载并显示在tableView中),最初我认为有些地方可能没有这些信息的数据,但试图寻找很多地方并添加一些断点我注意到可能问题是我用于网站的格式,价格水平和电话号码。这是Google地方详细信息的文档https://developers.google.com/places/ios-api/reference/interface_g_m_s_place.html#a08b7eb6929bc733c0e36cf36d82fa34b 有人可以帮我解决这个问题吗?