新手在这里。使用Google API附近搜索。我有问题将封装数据发送到封闭,已经填充了附近信息的表,但是当我尝试将placeID信息发送到闭包以获取详细信息时,它给我零。
这里我得到placeID和附近,然后用places数组填充tableView。 Class Place位于单独的swift文件中,函数downloadPlaceID位于ViewController内。
class Place {
var placeId: String!
var vicinity: String!
var _placeId: String {
if placeId == nil {
placeId = ""
}
return placeId
}
var _vicinity: String {
if vicinity == nil {
vicinity = ""
}
return vicinity
}
init( place: [String:Any]) {
if let ids = place["id"] as? String {
self.placeId = ids
}
if let vicinities = place["vicinity"] as? String {
self.vicinity = vicinities
}
}
}
func downloadPlaceID (completed: @escaping DownloadComplete) {
let placeURL = URL(string: nearbyURL)
Alamofire.request(placeURL!).responseJSON { (response) in
let result = response.result
if let dictionary = result.value as? [String:Any] {
if let results = dictionary["results"] as? [[String:Any]] {
if let status = dictionary["status"] as? String {
if status == "OK" {
for obj in results {
place = Place(place: obj)
// here i get all the placeID's
places.append(place)
}
}
}
}
}
completed()
}
}
然后我尝试获取详细信息,我放置了地址ID:
func downloadDetails( input: String, completed: DownloadComplete) {
let details = "\(detailsBaseURL)\(detailsPlaceId)\(input)\(detailsKey)\(detailsSearchAPIKey)"
print(placeID)
Alamofire.request(details).responseJSON { response in
let result = response.result
if let dictionary = result.value as? [String:Any] {
if let result = dictionary["result"] as? [String:Any] {
if let phoneNumber = result["formatted_phone_number"] as? String {
self.phone = phoneNumber
print(self.phone!)
}
if let geometry = result["geometry"] as? [String:Any] {
if let location = geometry["location"] as? [String:Any] {
if let latitude = location["lat"] as? Double {
self.lat = latitude
print(self.lat!)
}
if let longitude = location["lng"] as? Double {
self.lng = longitude
print(self.lng!)
}
}
}
if let openingHours = result["opening_hours"] as? [String:Any] {
if let openNow = openingHours["open_now"] as? Bool {
self.workHours = openNow
print(self.workHours!)
}
}
}
}
}
}
以下是我试图用来获取详细信息的viewDidLoad中的代码。
override func viewDidLoad() {
super.viewDidLoad()
downloadPlaceID {
detail.downloadDetails(input: place.placeId, completed: {
})
}
}
答案 0 :(得分:0)
应该是“place_id”而不是“id”
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:pi="urn:com.workday/picof">
<xsl:output method="text"/>
<xsl:template match="pi:Payroll_Extract_Employees/pi:company">
<xsl:variable name="test">
<xsl:text>pi:employee/pi:name</xsl:text>
</xsl:variable>
<xsl:variable name="names" as="element(name)*">
<xsl:evaluate xpath="$test" context-item="."/>
</xsl:variable>
<xsl:value-of select="$names"/>
</xsl:template>
</xsl:stylesheet>