-1

I am working on an iOS app which I need to pull locations from my database that are within a certain radius of the users location using longitudes and latitudes. I have a function that will determine the distance between two longitudes and latitudes in my php file. My thought was maybe I could try to pass the longitude and latitude of the users location to the php query then use that data and basically do a WHERE clause that would be if the distance found with that distance function was less than the radius I need to search. Is this possible? Is there a way to pass that kind of data form my objective C file to my php file? I am very new to databases so bear with me. Thanks!

coal175
  • 273
  • 1
  • 3
  • 10
  • `order by function_to_calculate_distance($where_you_are, location_of_current_record) asc having function_to_calculate_distance(...) < $max_allowed_distance)` – Marc B Jul 06 '15 at 15:34
  • Do you have an option to use PostgreSQL? – dikirill Jul 06 '15 at 15:36
  • There are many distinct problems here: Getting the location in IOS. Sending parameters along with an (http?) API call. Executing a query to get locations within X radius from a given point. Try to tackly them one by one. This question is *way* too broad now. – GolezTrol Jul 06 '15 at 15:37
  • Pass the data from your iOS app to your web app via `AFNetworking`. – JaredH Jul 06 '15 at 15:37
  • Check out this topic too http://stackoverflow.com/questions/13716313/mysql-function-to-calculate-distance-between-two-latitudes-and-longitudes – dikirill Jul 06 '15 at 15:38
  • But how do I get where_you_are's longitude and latitude I found in my Xcode project to my php file? In my Xcode project I find the users location or the location they searched and a radius they want to search but how can I use that data in my php file. – coal175 Jul 06 '15 at 15:39

1 Answers1

1

To solve this problem you need to send request in post or get method . then get the value from the post or get method . example: suppose your data in a server and your server name example.com then send longitudes and latitudes request using get method www.example.com?longitudes = 1000&latitudes = 5000;

in your php file get data that comes in get method

$longitudes  = $_GET['longitudes '];
$latitudes  = $_GET['latitudes '];

the send this variable in your where condition , then your problem is solved

tapos ghosh
  • 2,114
  • 23
  • 37
  • This looks like what I need! I will play around with it. I just found this, http://stackoverflow.com/questions/11778318/how-to-send-get-request-to-php-in-ios. Is this what you mean? – coal175 Jul 06 '15 at 17:14
  • Ok I have 1 more question. For my SELECT statement, is there any sort of iterator I can use to compare the longitudes and latitudes of the locations in the database to the longitude and latitude I got from the GET method? something like 'SELECT * FROM Locations WHILE distance(longitude, latitude, iterator.longitude, iterator.latitude) < radius' where distance finds the distance between the two points. – coal175 Jul 06 '15 at 18:32