本文整理汇总了Python中django.contrib.gis.utils.GeoIP.geos方法的典型用法代码示例。如果您正苦于以下问题:Python GeoIP.geos方法的具体用法?Python GeoIP.geos怎么用?Python GeoIP.geos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.gis.utils.GeoIP
的用法示例。
在下文中一共展示了GeoIP.geos方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test04_city
# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import geos [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)
示例2: test04_city
# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import geos [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)
示例3: neighborhood_monitoring
# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import geos [as 别名]
def neighborhood_monitoring(request,
template="geotags/view_neighborhood_monitoring.html",
content_type_name=None, distance_lt_km=None):
"""
Direct the user to a template that is able to render the `kml_neighborhood_feed`
on a google map. This feed can be restricted based on the content type of
the element you want to get.
"""
if distance_lt_km == None:
distance_lt_km = 10
gip=GeoIP()
if request.META["REMOTE_ADDR"] != "127.0.0.1":
user_ip = request.META["REMOTE_ADDR"]
else:
user_ip = "populous.com"
user_location_pnt = gip.geos(user_ip)
kml_feed = reverse("geotags-kml_neighborhood_feed",
kwargs={"distance_lt_km":distance_lt_km})
criteria_pnt = {
"point__distance_lt" : (user_location_pnt,
D(km=float(distance_lt_km))
)
}
geotag_points = Point.objects.filter(**criteria_pnt).distance(user_location_pnt).order_by("-distance")
context = RequestContext(request, {
"user_ip" : user_ip,
"user_location_pnt" : user_location_pnt,
"geotag_points" : geotag_points,
"google_key" : settings.GOOGLE_MAPS_API_KEY,
"user_city" : gip.city(user_ip),
"kml_feed" : kml_feed,
})
return render_to_response(template,context_instance=context)
示例4: kml_neighborhood_feed
# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import geos [as 别名]
def kml_neighborhood_feed(request, template="geotags/geotags.kml",
distance_lt_km=None ,content_type_name=None,
object_id=None):
"""
Return a KML feed of all the geotags in a around the user. This view takes
an argument called `distance_lt_km` which is the radius of the permeter your
are searching in. This feed can be restricted based on the content type of
the element you want to get.
"""
gip=GeoIP()
if request.META["REMOTE_ADDR"] != "127.0.0.1":
user_ip = request.META["REMOTE_ADDR"]
else:
user_ip = "populous.com"
user_location_pnt = gip.geos(user_ip)
criteria_pnt = {
"point__distance_lt" : (user_location_pnt,
D(km=float(distance_lt_km))
)
}
if content_type_name:
criteria_pnt["content_type__name"]==content_type_name
geotags = Point.objects.filter(**criteria_pnt)
context = RequestContext(request, {
'places' : geotags.kml(),
})
return render_to_kml(template,context_instance=context)
示例5: save
# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import geos [as 别名]
def save(self, *args, **kwargs):
g = GeoIP()
self.coords = g.geos(self.ip_address)
super(Hit, self).save(*args, **kwargs)
示例6: _set_location
# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import geos [as 别名]
def _set_location(self):
g = GeoIP()
self.location = g.geos(self.ip_address)