PFGeoPoint

Objective-C

@interface PFGeoPoint : NSObject <NSCopying, NSCoding>

Swift

class PFGeoPoint : NSObject, NSCopying, NSCoding

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..

Currently, instances of PFObject may only have one key associated with a PFGeoPoint type.

Creating a Geo Point

  • Create a PFGeoPoint object. Latitude and longitude are set to 0.0.

    Declaration

    Objective-C

    + (nonnull instancetype)geoPoint;

    Return Value

    Returns a new PFGeoPoint.

  • Creates a new PFGeoPoint object for the given CLLocation, set to the location’s coordinates.

    Declaration

    Objective-C

    + (nonnull instancetype)geoPointWithLocation:(nullable CLLocation *)location;

    Swift

    convenience init(location: CLLocation?)

    Parameters

    location

    Instace of CLLocation, with set latitude and longitude.

    Return Value

    Returns a new PFGeoPoint at specified location.

  • Create a new PFGeoPoint object with the specified latitude and longitude.

    Declaration

    Objective-C

    + (nonnull instancetype)geoPointWithLatitude:(double)latitude
                                       longitude:(double)longitude;

    Swift

    convenience init(latitude: Double, longitude: Double)

    Parameters

    latitude

    Latitude of point in degrees.

    longitude

    Longitude of point in degrees.

    Return Value

    New point object with specified latitude and longitude.

  • Fetches the current device location and executes a block with a new PFGeoPoint object.

    @discussion You should not block the main thread while calling this method, as underneath, it makes a call to UIApplication.applicationState that requires to be on the main thread.

    If you were to use a semaphore wait/signal to ‘wait’ for the result, you’d effectively deadlock your app.

    Declaration

    Objective-C

    + (void)geoPointForCurrentLocationInBackground:
        (nullable PFGeoPointResultBlock)resultBlock;

    Swift

    class func geoPointForCurrentLocation(inBackground resultBlock: PFGeoPointResultBlock? = nil)

    Parameters

    resultBlock

    A block which takes the newly created PFGeoPoint as an argument. It should have the following argument signature: ^(PFGeoPoint *geoPoint, NSError *error)

Controlling Position

  • Latitude of point in degrees. Valid range is from -90.0 to 90.0.

    Declaration

    Objective-C

    @property (nonatomic) double latitude;

    Swift

    var latitude: Double { get set }
  • Longitude of point in degrees. Valid range is from -180.0 to 180.0.

    Declaration

    Objective-C

    @property (nonatomic) double longitude;

    Swift

    var longitude: Double { get set }

Calculating Distance

  • Get distance in radians from this point to specified point.

    Declaration

    Objective-C

    - (double)distanceInRadiansTo:(nullable PFGeoPoint *)point;

    Swift

    func distanceInRadians(to point: PFGeoPoint?) -> Double

    Parameters

    point

    PFGeoPoint that represents the location of other point.

    Return Value

    Distance in radians between the receiver and point.

  • Get distance in miles from this point to specified point.

    Declaration

    Objective-C

    - (double)distanceInMilesTo:(nullable PFGeoPoint *)point;

    Swift

    func distanceInMiles(to point: PFGeoPoint?) -> Double

    Parameters

    point

    PFGeoPoint that represents the location of other point.

    Return Value

    Distance in miles between the receiver and point.

  • Get distance in kilometers from this point to specified point.

    Declaration

    Objective-C

    - (double)distanceInKilometersTo:(nullable PFGeoPoint *)point;

    Swift

    func distanceInKilometers(to point: PFGeoPoint?) -> Double

    Parameters

    point

    PFGeoPoint that represents the location of other point.

    Return Value

    Distance in kilometers between the receiver and point.