Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header("Content-Type: application/json");
- $host = 'localhost';
- $mysql_username = 'mosqueks';
- $mysql_password = 'Arwa@1339';
- $database = 'mosqueks_WPQKR';
- $connect = MYSQLI_CONNECT($host, $mysql_username, $mysql_password) ;
- if (mysqli_connect_errno()){
- die("cannot connect to database".mysqli_connect_error());
- }
- echo 'Connected successfully';
- $latitude = $_REQUEST["latitude"];
- $longitude= $_REQUEST["longitude"];
- $myArray = array();
- if ($result = $mysqli->query("SELECT * , (6371 * 2 * ASIN(SQRT(
- POWER(SIN(( .$latitude. - Latitude) * pi()/180 / 2), 2)
- +COS(.$latitude.* pi()/180) * COS(Latitude * pi()/180) * POWER(SIN((
- .$longitude. - Longitude) * pi()/180 / 2), 2) ))) as distance from
- mosque HAVING distance < 5 order by distance")) {
- $myArray = $result->fetch_all(MYSQLI_ASSOC);
- }
- echo json_encode($myArray);
- ?>
- import UIKit
- class retriveM: NSObject,URLSessionDataDelegate {
- var data : NSMutableData = NSMutableData()
- func retrieveNearest(lat:Double,long:Double){
- let url = NSMutableURLRequest(url: NSURL(string:
- "http://mosqueksu.com/mosqueksu/retrieveNearest.php")! as URL )
- url.httpMethod = "POST"
- let postString = "latitude=(lat),longitude=(long)"
- // Alamofire.request(.GET,url).responseJSON { response in
- url.httpBody = postString.data(using: String.Encoding.utf8)
- var session: URLSession!
- let configuration = URLSessionConfiguration.default
- session = URLSession(configuration: configuration, delegate: self, delegateQueue: nil)
- let task = session.dataTask(with: url as URLRequest)
- task.resume()
- }
- func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data)
- {
- self.data.append(data as Data);
- }
- func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?)
- {
- if error != nil
- {
- print("Not Found", error as Any )
- }
- else
- {
- print("Ok")
- self.parseJSON()
- }
- }
- func parseJSON()
- {
- var jsonResult: NSArray = NSArray()
- do
- {
- // jsonResult = try JSONSerialization.jsonObject(with: data as Data, options: .allowFragments) as! NSArray
- jsonResult = try JSONSerialization.jsonObject(with: data as Data, options: .allowFragments) as! NSArray
- print("jsonResult.count",jsonResult.count)
- }
- catch let error as NSError
- {
- print("jsonResult: ", error)
- }
- var jsonElement: NSDictionary = NSDictionary()
- var contador = 0
- for i in (0..<jsonResult.count)
- {
- jsonElement = jsonResult[i] as! NSDictionary
- if let id = jsonElement["OBJECTID"] as? Int,
- let name = jsonElement["ArabicName"] as? String,
- let nameE = jsonElement["EnglishName"] as? String,
- let lat = jsonElement["latitude"] as? Double,
- let long = jsonElement["longitude"] as? Double,
- let status = jsonElement["status"] as? String
- {
- print("id: ", id)
- print("name: ", name)
- print("nameE: ", nameE)
- print("latitude",lat)
- print("longitude",long)
- print ("status",status)
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment