How can i show in Google Map the nearest places to my location?

岁酱吖の 提交于 2019-12-23 04:48:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!