/RealmGeoQueries

Realm GeoQueries made easy

Primary LanguageSwiftApache License 2.0Apache-2.0

RealmGeoQueries

issuesstarslicense

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, '8.0'
pod "RealmGeoQueries"

Manually installation

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

Requirements

Version Language Minimum iOS Target
1.x Swift iOS 8

Usage

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; ```swift let results = try! Realm() .findInRegion(YourModelClass.self, region: mapView.region) ```

Search around the center with radius in meters;

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

Filter Realm results with radius in meters;

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

See GeoQueries.swift for more options.

Contact

License

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