本文整理汇总了Python中django.contrib.gis.utils.GeoIP.lon_lat方法的典型用法代码示例。如果您正苦于以下问题:Python GeoIP.lon_lat方法的具体用法?Python GeoIP.lon_lat怎么用?Python GeoIP.lon_lat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.gis.utils.GeoIP
的用法示例。
在下文中一共展示了GeoIP.lon_lat方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_geoip_position
# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import lon_lat [as 别名]
def get_geoip_position(request):
"""Returns the user's position as a (lat, lng) tuple based on his IP."""
result = (None, None)
g = GeoIP()
ip = (request.META.get('HTTP_X_FORWARDED_FOR')
or request.META.get('REMOTE_ADDR'))
result = g.lon_lat(ip)
if result is None:
ip = settings.SERVER_IP
result = g.lon_lat(ip)
if result is None:
return None
return (result[1], result[0])
示例2: test04_city
# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import lon_lat [as 别名]
def test04_city(self):
"Testing GeoIP city querying methods."
g = GeoIP(country='<foo>')
addr = '130.80.29.3'
fqdn = 'chron.com'
for query in (fqdn, addr):
# Country queries should still work.
for func in (g.country_code, g.country_code_by_addr, g.country_code_by_name):
self.assertEqual('US', func(query))
for func in (g.country_name, g.country_name_by_addr, g.country_name_by_name):
self.assertEqual('United States', func(query))
self.assertEqual({'country_code' : 'US', 'country_name' : 'United States'},
g.country(query))
# City information dictionary.
d = g.city(query)
self.assertEqual('USA', d['country_code3'])
self.assertEqual('Houston', d['city'])
self.assertEqual('TX', d['region'])
self.assertEqual(713, d['area_code'])
geom = g.geos(query)
self.failIf(not isinstance(geom, GEOSGeometry))
lon, lat = (-95.3670, 29.7523)
lat_lon = g.lat_lon(query)
lat_lon = (lat_lon[1], lat_lon[0])
for tup in (geom.tuple, g.coords(query), g.lon_lat(query), lat_lon):
self.assertAlmostEqual(lon, tup[0], 4)
self.assertAlmostEqual(lat, tup[1], 4)
示例3: test04_city
# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import lon_lat [as 别名]
def test04_city(self):
"Testing GeoIP city querying methods."
g = GeoIP(country="<foo>")
addr = "130.80.29.3"
fqdn = "chron.com"
for query in (fqdn, addr):
# Country queries should still work.
for func in (g.country_code, g.country_code_by_addr, g.country_code_by_name):
self.assertEqual("US", func(query))
for func in (g.country_name, g.country_name_by_addr, g.country_name_by_name):
self.assertEqual("United States", func(query))
self.assertEqual({"country_code": "US", "country_name": "United States"}, g.country(query))
# City information dictionary.
d = g.city(query)
self.assertEqual("USA", d["country_code3"])
self.assertEqual("Houston", d["city"])
self.assertEqual("TX", d["region"])
self.assertEqual(713, d["area_code"])
geom = g.geos(query)
self.failIf(not isinstance(geom, GEOSGeometry))
lon, lat = (-95.4152, 29.7755)
lat_lon = g.lat_lon(query)
lat_lon = (lat_lon[1], lat_lon[0])
for tup in (geom.tuple, g.coords(query), g.lon_lat(query), lat_lon):
self.assertAlmostEqual(lon, tup[0], 4)
self.assertAlmostEqual(lat, tup[1], 4)