Skip to content

Commit 8e88a83

Browse files
author
Mark Costello
committed
Convert longitude and latitude to floats, update the readme
1 parent 8dbc62c commit 8e88a83

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ Download the tarball, untar and run `python setup.py install`
3737
The following returns the information as a python object
3838
"""
3939
pylocinfo = pyloc.info
40-
pylocinfo.ip => '8.8.8.8'
41-
pylocinfo.city => 'Mountain View, CA'
42-
pylocinfo.country_name => 'UNITED STATES'
43-
pylocinfo.country_code => 'US'
44-
pylocinfo.latitude => '37.402'
45-
pylocinfo.longitude => '-122.078'
40+
print pylocinfo.ip # '8.8.8.8'
41+
print pylocinfo.city # 'Mountain View, CA'
42+
print pylocinfo.country_name # 'UNITED STATES'
43+
print pylocinfo.country_code # 'US'
44+
print pylocinfo.latitude # 37.402
45+
print pylocinfo.longitude # -122.078
4646

4747

4848
"""

pylocation/core.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,14 @@ def __init__(self, properties):
5353
self.city = properties['city']
5454
self.country_name = properties['country_name']
5555
self.country_code = properties['country_code']
56-
self.latitude = properties.get('lat', None)
57-
self.longitude = properties.get('lng', None)
56+
self.latitude = None
57+
self.longitude = None
58+
latitude = properties.get('lat', None)
59+
if latitude:
60+
self.latitude = float(latitude)
61+
longitude = properties.get('lng', None)
62+
if latitude:
63+
self.longitude = float(longitude)
5864

5965
class PyLocation(object):
6066
"""The :class `PyLocation` object. Used to perform the various operations

0 commit comments

Comments
 (0)