当前位置: 首页>>代码示例>>Python>>正文


Python GeoIP.coords方法代码示例

本文整理汇总了Python中django.contrib.gis.utils.GeoIP.coords方法的典型用法代码示例。如果您正苦于以下问题:Python GeoIP.coords方法的具体用法?Python GeoIP.coords怎么用?Python GeoIP.coords使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.contrib.gis.utils.GeoIP的用法示例。


在下文中一共展示了GeoIP.coords方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test04_city

# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import coords [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)
开发者ID:GoSteven,项目名称:Diary,代码行数:31,代码来源:test_geoip.py

示例2: test04_city

# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import coords [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)
开发者ID:greggian,项目名称:TapdIn,代码行数:30,代码来源:test_geoip.py

示例3: checkin

# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import coords [as 别名]
def checkin(request):
    ip = request.META['REMOTE_ADDR']
    geoip = GeoIP()
    coords = geoip.coords(ip)
    if not coords:
        coords = (0, 0)
    if request.method == "POST":
        form = CheckinForm(request.POST)
        if form.is_valid():
            checkin = form.save(commit=False)
            checkin.type = '1'
            checkin.geodata = Point(coords)
            checkin.save()
        if request.is_ajax():
            return HttpResponse("{response: 'ok'}", mimetype="application/json")
        else:
            HttpResponseRedirect('/')
    else:
        form = CheckinForm()
    return render_to_response('checkin.html', {'form':form},
        RequestContext(request))
开发者ID:rootart,项目名称:geojam,代码行数:23,代码来源:views.py

示例4: dashboard

# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import coords [as 别名]
def dashboard(request):
    ip = request.META['REMOTE_ADDR']
    geoip = GeoIP()
    
    try:
        country = geoip.country(ip)
    except:
        country = "Ghost"
    else:
        country = country['country_name']
    
    try:
        coords = geoip.coords(ip)
        if not coords:
            coords = "on Earth"
    except:
        coords = "on Earth"
    
    location = {
        'country': country,
        'coords': coords
    }
    
    checkins = Checkin.objects.all()
    obj_list = list()
    for item in checkins:
        item.geodata.transform(900913)
        obj_list.append(json.loads(item.geodata.geojson))
    obj_list = json.dumps(obj_list)

    last_20 = Checkin.objects.all()[:19]
    data = {
        "checkins": last_20,
        "count": Checkin.objects.all().count(),
        "obj_list": obj_list,
        "location": location
        }
    return render_to_response("index.html", data,
        context_instance=RequestContext(request, {}))
开发者ID:rootart,项目名称:geojam,代码行数:41,代码来源:views.py


注:本文中的django.contrib.gis.utils.GeoIP.coords方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。