user4184036
user4184036

Reputation:

Learning the difference between Parse Geopoint and CoreLocation

I am new to programming and trying to learn swift, although I am now trying to broaden on location services and how to access a users location.

I am creating an app where I use Parse backend to store users, and I also want it to store the users locations, and then be able to project those users locations as annotations onto a map. Theres a lot of documentation out there which can be quite overwhelming which shows you how to get a users location with both Parse geopoint and coreLocation. If somebody could help explain the actual benefits of using each one and how/why I could use this maybe in what I am trying to achieve?

Thanks in advance.

Upvotes: 0

Views: 758

Answers (1)

ahtierney
ahtierney

Reputation: 318

From the documentation

The purpose of Core Location framework is defined as :

The Core Location framework lets you determine the current location or heading associated with a device. The framework uses the available hardware to determine the user’s position and heading.

The Purpose of PFGeopoint is defined as:

PFGeoPoint may be used to embed a latitude / longitude point as the value for a key in a PFObject. It could be used to perform queries in a geospatial manner using [PFQuery whereKey:nearGeoPoint:].

CoreLocation is a framework, PFGeoPoint is a class. This is to say that broadly CoreLocation is a suite of tools used to interface with a device's hardware and ask it questions about it's current position (where is it, what direction is it facing) and the classes that provide those services. PFGeoPoint on the other hand, is a class that is part of Parse's framework, used to interface with Parse and store/query your Parse back end for geographic information. Parse provides a connivence method:

+ (void)geoPointForCurrentLocationInBackground:(void ( ^ ) ( PFGeoPoint *geoPoint , NSError *error ))geoPointHandler

which would use CoreLocation under the hood to get the PFGeoPoint that represents the current device's current location. If ultimately you're looking to plot these points on a map, really what you're looking for is a pair of numbers, a latitude and a longitude that represent the current user. You can get this by going through Parse via the method above (each PFGeoPoint object has a lat and a lon), or through using CoreLocation directly (each CLLocation has a CLLocationCoordinate2D object which has a lat and lon).

Hopefully this get's you pointed in the right direction. I know the docs can be daunting at first but hang in there and don't fear them, it all starts to make sense the more you read and explore.

Upvotes: 3

Related Questions