Swiftpack.co - Package - mhergon/RealmGeoQueries


cocoapods carthage issues stars license

RealmGeoQueries simplifies spatial queries with Realm Cocoa. In the absence of and official functions, this library provide the possibility to do proximity search. It's not necessary to include Geohash or other types of indexes in the model class as it only needs latitude and longitude properties.

How To Get Started

Installation with CocoaPods

platform :ios, '9.0'
pod "RealmGeoQueries"

Installation with Carthage

Add to mhergon/RealmGeoQueries project to your Cartfile

github "mhergon/RealmGeoQueries"

Drag GeoQueries.framework, RealmSwift.framework and Realm.framework from Carthage/Build/ to the “Linked Frameworks and Libraries” section of your Xcode project’s “General” settings.

Only on iOS/tvOS/watchOS: On your application targets "Build Phases" settings tab, click the "+" icon and choose "New Run Script Phase". Create a Run Script with the following contents:

/usr/local/bin/carthage copy-frameworks

and add the paths to the frameworks you want to use under "Input Files", e.g.:


Swift Package Manager

Once you have your Swift package set up, adding RealmGeoQueries as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/mhergon/RealmGeoQueries.git", from: "1.4.0")

Manually installation

Download (right-click) and add to your project.


| Version | Language | Minimum iOS Target | |:--------------------:|:---------------------------:|:---------------------------:| | 1.4 | Swift 5.x / Realm 5.x | iOS 9 | | 1.3 | Swift 4.x / Realm 3.x | iOS 9 | | 1.2 | Swift 3.0 / Realm 2.x | iOS 9 | | 1.1 | Swift 2.x / Realm 2.x | iOS 8 |


First, import module;

import GeoQueries

Model must have a latitude and longitude keys, that have to be named "lat" and "lng" respectively. You can use another property names (use "latitudeKey" and "longitudeKey" parameters).

Search with MapView MKCoordinateRegion;

let results = try! Realm()
    .findInRegion(type: YourModelClass.self, region: mapView.region)

Search around the center with radius in meters;

let results = try! Realm()
    .findNearby(type: YourModelClass.self, origin: mapView.centerCoordinate, radius: 500, sortAscending: nil)

Filter Realm results with radius in meters;

let results = try! Realm()
    .filter("type", "restaurant")
    .filterGeoRadius(center: mapView.centerCoordinate, radius: 500, sortAscending: nil)

See GeoQueries.swift for more options.



Licensed under Apache License v2.0.
Copyright 2020 Marc Hervera.


Stars: 134


Used By

Total: 0


Added SPM - 2020-01-09 17:02:40

Realm GeoQueries made easy - 2019-03-14 17:57:19

  • Fixed MapKit deprecations

Realm GeoQueries made easy - 2018-02-08 09:23:37

  • Public Geobox parameters and init

Realm GeoQueries made easy - 2017-10-18 07:05:05

  • Added support for Swift 4.x and Realm 3.x
  • Added compatibility to search on List and Results
  • Added tests

Realm GeoQueries made easy - 2017-10-04 11:43:37

Added support to Swift 4 and Realm 3.0.0.rc-1

Realm GeoQueries made easy - 2017-04-22 10:47:25

Added Carthage support

Realm GeoQueries made easy - 2016-10-15 16:48:12

Swift 3.0 version

Realm GeoQueries made easy - 2015-12-16 11:33:14

Performance improvements Deleted "distanceKey" Added "sortByDistance" for sort Results

Realm GeoQueries made easy - 2015-12-15 21:07:22

Fixed queries bug