Search code examples
iosdjangoswiftamazon-web-servicesgeolocation

How to fetch location based content when a user is at a specific location?


I'm creating an iOS app where say a user1 can drop an image at a certain location, that image gets sent to the database (Django on aws) and gets stored with the fields: image link, locLong and locLat.

Now, when user2 arrives at the same location, it will fetch the image from the server and display on user2's phone. When the image is displayed on user2's phone, it is gone from the database and the object containing the lat and long are deleted, thus an image can be picked only once by a user, but a user can drop multiple pictures anywhere they like. They will be saved until someone else comes along and "picks" them up.

The problem I face is that I am not sure how to compare user2's location against many pictures in the database that might have been dropped where user2 could be many different users walking along.

I am using Django, and I send and receive data using the rest api, where the data sent and received is in JSON format.

I am new to Django and iOS, so perhaps I might be missing something obvious backend wise?

Perhaps my models for saving data on the server are not correct, maybe there is a better approach to this problem using a different type of model?

I have seen questions where one can find out if a person is within a certain radius or not here. But the locations in my app won't be hardcoded, as they can change all the time and the database will keep track of that.

My models in Django are setup like this

user
  - name
  - email
  - image url

image
  - OneToOneField(user)
  - image url
  - locLat
  - locLong

Solution

  • Basically you don't compare the "location". You do geospatial querys to fetch images/objects in a radius around a certain given long/lat (user2s long lat). Where the inputs will be Radius / Longitude / Latitude for your query.

    I am not familiar with django but a basic google got me to this: GeoSpatial for Django(?)