Guest User

Untitled

a guest
Feb 14th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. <?php
  2. header("Content-Type: application/json");
  3.  
  4. $host = 'localhost';
  5. $mysql_username = 'mosqueks';
  6. $mysql_password = 'Arwa@1339';
  7. $database = 'mosqueks_WPQKR';
  8.  
  9.  
  10. $connect = MYSQLI_CONNECT($host, $mysql_username, $mysql_password) ;
  11.  
  12. if (mysqli_connect_errno()){
  13.  
  14. die("cannot connect to database".mysqli_connect_error());
  15. }
  16.  
  17. echo 'Connected successfully';
  18.  
  19. $latitude = $_REQUEST["latitude"];
  20. $longitude= $_REQUEST["longitude"];
  21.  
  22. $myArray = array();
  23. if ($result = $mysqli->query("SELECT * , (6371 * 2 * ASIN(SQRT(
  24. POWER(SIN(( .$latitude. - Latitude) * pi()/180 / 2), 2)
  25. +COS(.$latitude.* pi()/180) * COS(Latitude * pi()/180) * POWER(SIN((
  26. .$longitude. - Longitude) * pi()/180 / 2), 2) ))) as distance from
  27. mosque HAVING distance < 5 order by distance")) {
  28.  
  29. $myArray = $result->fetch_all(MYSQLI_ASSOC);
  30. }
  31. echo json_encode($myArray);
  32.  
  33. ?>
  34.  
  35. import UIKit
  36. class retriveM: NSObject,URLSessionDataDelegate {
  37.  
  38. var data : NSMutableData = NSMutableData()
  39.  
  40. func retrieveNearest(lat:Double,long:Double){
  41.  
  42. let url = NSMutableURLRequest(url: NSURL(string:
  43. "http://mosqueksu.com/mosqueksu/retrieveNearest.php")! as URL )
  44. url.httpMethod = "POST"
  45. let postString = "latitude=(lat),longitude=(long)"
  46. // Alamofire.request(.GET,url).responseJSON { response in
  47. url.httpBody = postString.data(using: String.Encoding.utf8)
  48. var session: URLSession!
  49.  
  50. let configuration = URLSessionConfiguration.default
  51.  
  52. session = URLSession(configuration: configuration, delegate: self, delegateQueue: nil)
  53.  
  54. let task = session.dataTask(with: url as URLRequest)
  55.  
  56. task.resume()
  57.  
  58.  
  59. }
  60.  
  61.  
  62.  
  63. func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data)
  64. {
  65. self.data.append(data as Data);
  66. }
  67.  
  68.  
  69.  
  70. func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?)
  71. {
  72. if error != nil
  73. {
  74. print("Not Found", error as Any )
  75.  
  76. }
  77. else
  78. {
  79. print("Ok")
  80. self.parseJSON()
  81. }
  82.  
  83. }
  84.  
  85.  
  86. func parseJSON()
  87. {
  88.  
  89. var jsonResult: NSArray = NSArray()
  90.  
  91. do
  92. {
  93. // jsonResult = try JSONSerialization.jsonObject(with: data as Data, options: .allowFragments) as! NSArray
  94. jsonResult = try JSONSerialization.jsonObject(with: data as Data, options: .allowFragments) as! NSArray
  95.  
  96. print("jsonResult.count",jsonResult.count)
  97. }
  98. catch let error as NSError
  99. {
  100. print("jsonResult: ", error)
  101. }
  102.  
  103.  
  104. var jsonElement: NSDictionary = NSDictionary()
  105. var contador = 0
  106. for i in (0..<jsonResult.count)
  107. {
  108. jsonElement = jsonResult[i] as! NSDictionary
  109.  
  110. if let id = jsonElement["OBJECTID"] as? Int,
  111. let name = jsonElement["ArabicName"] as? String,
  112. let nameE = jsonElement["EnglishName"] as? String,
  113. let lat = jsonElement["latitude"] as? Double,
  114. let long = jsonElement["longitude"] as? Double,
  115. let status = jsonElement["status"] as? String
  116. {
  117. print("id: ", id)
  118. print("name: ", name)
  119. print("nameE: ", nameE)
  120. print("latitude",lat)
  121. print("longitude",long)
  122. print ("status",status)
  123. }
  124.  
  125. }
  126. }
  127. }
Add Comment
Please, Sign In to add comment