Question

I am working on an app for iOS 7 and I need to find the location of the user and then check to see what other users are also at that same location. I need it to update as soon as the user opens the app as well as update every so often and will display the users at the same location. I have looked at the available examples, but there doesn't seem to be enough on this using Parse. Can anyone give me any help on how to go about doing this, or if anyone knows of some examples similar to what I'm trying to do I would greatly appreciate it. Thanks in advance!

Was it helpful?

Solution

You need to break your problem down and tackle the various pieces -

  1. Obtain the user's location when the app opens and periodically The Location and Maps programming guide is a good starting point. You can use CLLocationManager to obtain your initial location and you can register for the significant location change event to get updates periodically, even when your app isn't running. Apple has example code plus there are plenty of other examples out there - Just search using "Core Location examples"
  2. Store the user's location in your Parse database There are examples and documentation on Parse.com showing how to do this. You can also provide a web service that allows your app to query the database for other users at the same location
  3. Identify other users at the same location when your app isn't running You can use Parse background jobs to trawl your database, match user locations and send push notifications to your users. Again there are examples on Parse.com showing how to set up background jobs and push notifications

OTHER TIPS

this may help this will get your current location then save to parse, its just a matter of querying parse to pull the data down

func locationManager(manager: CLLocationManager!, didUpdateLocations  
locations: [AnyObject]!) {

    var userLocation : CLLocation = locations[0] as! CLLocation

    var latitude = userLocation.coordinate.latitude
    var longitude = userLocation.coordinate.longitude

    var latDelta : CLLocationDegrees = 0.01
    var lonDelta : CLLocationDegrees = 0.01

    var span : MKCoordinateSpan = MKCoordinateSpanMake(latDelta,  
    lonDelta)

    var location : CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude)
    var region : MKCoordinateRegion = MKCoordinateRegionMake(location, span)

    self.mapView.setRegion(region, animated: true)

    let testObject = PFObject(className: "User")

    let currentPoints = PFGeoPoint(latitude: latitude, longitude: longitude)

    testObject.setValue(currentPoints, forKey: "currentLocation")

    testObject.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in

        if (success) {

            dispatch_async(dispatch_get_main_queue()) {

                println("added to parse")
            }


        } else {

            println(error)

        }

    }

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top