问题
Im trying to create an iOS App, i'm not entirely sure about a few things with swift by now, but i´m still learning every day!
My question is...
How can i show in Google Map the nearest places to my location?! Im getting an array from mysql DB with Latitude & Longitude, but i can't (i have no idea) how to place those selected records in my map! (i mean a determined radius from my location) would somebody help me please?!
iOS #MySQL #JSON #GoogleMapsSDK #Swift3
I'm using AlamoFire & Swifty PODs to work with the arrays
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()
}
There's my func to receive an array with data fields i put into variables, after that i can place it in a tableViewController or show markers with GoogleMapsSDK . The thing is that i have an X number of rows but i just want to show those who are nearby located!!!
来源:https://stackoverflow.com/questions/43332596/how-can-i-show-in-google-map-the-nearest-places-to-my-location