GithubHelp home page GithubHelp logo

ininex / geofire-python Goto Github PK

View Code? Open in Web Editor NEW
6.0 4.0 5.0 22.48 MB

GeoFire for Python

License: MIT License

Python 99.83% Shell 0.04% C 0.04% JavaScript 0.05% CSS 0.05%
geofire python proximity geolocation query geohash

geofire-python's Introduction

GeoFire-Python

GeoFire for Python (v0.3)

A Firebase geo-query library: GeoFire for Python

Contributors

  • Guanjiu Zhang

Installation

    pip install GeoFire-Python

Module Import

    from GeoFire.geofire import GeoFire

Usage Example

  • Put following code into a python file (eg. example.py) and run on local server
    from GeoFire.geofire import GeoFire

    app = Flask(__name__)

    @app.route('/')
    def example():
        geofire = GeoFire(lat = 42.26853470728501,
                       lon = -83.7487,
                       radius = 25,
                       unit = 'km').config_firebase(
            api_key='AIzaSyDk7YcWydJ66LNNP05KaSb2lkaZH5HGNIc',
            auth_domain='geofire-python-example.firebaseapp.com',
            database_URL='https://geofire-python-example.firebaseio.com',
            storage_bucket='geofire-python-example.appspot.com'
        )
        nearby_people_details = geofire.query_nearby_objects(query_ref='Locations',
                                            geohash_ref='geohash')
        nearby_info = []
        for nearby_person_detail in nearby_people_details.values():
            nearby_info.append(" {0} is at {1}.".format(nearby_person_detail['name'], nearby_person_detail['place_name']))
        return jsonify({'nearby_people': nearby_info})


    if __name__ == '__main__':
        app.run(debug=True)

  • Type following address in your browser to see example database structure:
    https://geofire-python-example.firebaseio.com/.json?print=pretty
  • Type following rules in your Firebase Rules:
{
  "rules": {
    ".read": true,
    ".write": true,
    "Locations": {
       ".indexOn":"geohash"
    }
  }
}

geofire-python's People

Contributors

ininex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

geofire-python's Issues

Changing search radius does not change the returned results

Changing the search radius should result in changing number of results. I find that the entire geofire database is returned each time

test code

from GeoFire.geofire import GeoFire

for radius in [0,10,25,50]:

	geofire = GeoFire(lat = 43.0,
				lon = -84.0,
				radius = radius,
				unit = 'km').config_firebase(
			api_key='AIzaSyDk7YcWydJ66LNNP05KaSb2lkaZH5HGNIc',
			auth_domain='geofire-python-example.firebaseapp.com',
			database_URL='https://geofire-python-example.firebaseio.com',
			storage_bucket='geofire-python-example.appspot.com')

	nearby_people_details = geofire.query_nearby_objects(query_ref='Locations',geohash_ref='geohash')

	print radius, len(nearby_people_details)

prints

0 3
10 3
25 3
50 3

meaning that for all values of radius, the same results are returned. Please note that I also rounded down the input latitude/longitude...

I can add that looking at the GeoFire Java class, specifically GeoHashQuery.java, in function queriesAtLocation the radius is converted to a latitude/longitude, and then converted to startValue and endValue as well as geohash in the function queryForGeoHash.

But in the Python version, current line 75 of GeoFire.py

  start_at(search_region_hash).end_at(search_region_hash + '\uf8ff').get(token=token_id).val()

end end_at value is just the search_region_hash plus a unicode character, and has nothing to do with the input radius. The geohash.expand() function is used (current line 63), but doesn't include any mention to radius.

From the input latitude/longitude, the geohash.expand() function is then creating this array of geohashes

['dpe', 'dpt', 'dpk', 'dp7', 'dpm', 'dpu', 'dpg', 'dpv', 'dps']

But as you can see from the length, this is a huge area, with each geohash corresponding to about 80 km, and therefore all the queries are returning all the results.

Security rules for firebase DB

Can you please share security rules you wrote in db, I am not able to identify specific entry in db.

It gives me "Index not defined" error. I have tried alot of stuff but it fails. So it would be big help if you just share security rules

Doesn't support python3

Traceback (most recent call last):
File "/Users/matthew/Desktop/Telus/ddb.py", line 1, in
from GeoFire.geofire import GeoFire
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/GeoFire/geofire.py", line 2, in
from pyrebase import pyrebase
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pyrebase/init.py", line 1, in
from .pyrebase import initialize_app
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pyrebase/pyrebase.py", line 1, in
import requests
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/init.py", line 63, in
from . import utils
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/utils.py", line 27, in
from .cookies import RequestsCookieJar, cookiejar_from_dict
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/cookies.py", line 172, in
class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping):

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.