我试图创建一个iOS应用程序,我现在还不能完全确定一些快速的东西,但我仍然每天都在学习!
我的问题是......
如何在Google地图中显示离我所在位置最近的地方?!我从谷歌数据库中获取了一个带谷歌纵横和数字的数组经度,但我不能(我不知道)如何将这些选定的记录放在我的地图中! (我的意思是从我的位置确定的半径) 有人会帮我吗?!
我正在使用 AlamoFire & Swifty 用于处理数组的POD
func getDatos(){
let key = "654321"
let postString = "buscar=\(self.searchtext)&key=\(key)" //-----------------data send post ///-------- SEARCH
let url = URL(string: "http://myWeb.com/myFile.php")! ///-------- SEARCH
print(url)
var request = URLRequest(url: url)
request.httpMethod = "POST" //-----------sending -> post method
request.httpBody = postString.data(using: .utf8) //---------------concatenate my variables with utf8 coding
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else { //---------------if error do exist finish the func
print("failed request \(String(describing: error))") //---------------mannage the error
return //------------- break code block
}
do {//----------- create son object
if let json = try JSONSerialization.jsonObject(with: data) as? [NSDictionary] {
DispatchQueue.main.async { //-----------------main process
for result in json {
let id = result["id"] as! String
let country = result["country"] as! String
let lati = result["lati"] as! String
let long = result["long"] as! String
self.idCountry.append(id) //--------------------push elements into array
self.ctryCountry.append(country)
self.latiCountry.append(lati)
self.longCountry.append(long)
}
self.tableView.reloadData() //-------------------reload table again
}
}
} catch let parseError { //------------------mannage error
print("parsing error: \(parseError)")
let responseString = String(data: data, encoding: .utf8)
print("response : \(String(describing: responseString))")
}
}
task.resume()
}
有我的func接收带有数据字段的数组我放入变量,之后我可以将它放在tableViewController中或用GoogleMapsSDK显示标记。问题是我有X行,但我只想展示附近的人!!!