我已经创建了一个应用程序,也已经创建了一个api,我必须从api中获取数据并在主屏幕中显示它。我已经附上了我的代码,目前我给出了默认的纬度和经度值。帮我这个
let stateLoc = plistHelper.readPlist(namePlist: "contacts", key: "isChildWithMe")
let API_URL: String?
if stateLoc as! String == "y"{
let lat = -37.87255
let long = 145.02262
API_URL = "http://142.93.120.204/plumber/Json?lat=\(lat)&lon=\(long)"
print(API_URL!)
}
else{
let lat = plistHelper.readPlist(namePlist: "contacts", key: "lat")
let long = plistHelper.readPlist(namePlist: "contacts", key: "long")
API_URL = "http://142.93.120.204/plumber/Json?lat=\(lat)&lon=\(long)"
print(API_URL!)
}
// Download the API Data
currentWeather.downloadCurrentWeather(api_url: API_URL!) {
// Update the UI after download is completed.
self.updateUI()
}
}
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
currentLocation = (locations[locations.count-1] as! CLLocation)
print("locations = \(currentLocation)")
// lbl1.text = "\(currentLocation.coordinate.latitude)";
// lbl2.text = "\(currentLocation.coordinate.longitude)";
}`
位置名称应显示设备位置