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


Python GeoIP.lat_lon方法代码示例

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


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

示例1: test04_city

# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import lat_lon [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 lat_lon [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: browse_offers

# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import lat_lon [as 别名]
def browse_offers(request):
    """
    """
    if request.user.is_authenticated():
        userprofile = request.user.get_profile()
    else:
        userprofile = None

    if request.method == 'POST' or request.GET.get('page'):
        if request.is_ajax():
            return list_offers(request)

        offers, form = get_offers(request.REQUEST, {'asking_userprofile':userprofile})
        if form.errors:
            if request.is_ajax():
                return JsonResponse({'errors': form.errors})
            else:
                return render_to_response_context(
                    request,
                    'offers/browse_offers.html',
                    {'form': form,
                     'offers': []})
    else:
        if userprofile and userprofile.location:
            lng, lat = userprofile.location.coords
            location_source = 'userprofile'
        else:
            g = GeoIP()
            ip = request.META.get('REMOTE_ADDR')
            lat, lng = 52.63639666, 1.29432678223
            location_source = 'none'
            if ip:
                latlon = g.lat_lon(ip)
                if latlon:
                    lat, lng = latlon
                    location_source = 'ip'
        form = OfferBrowseForm(initial={'max_distance': 25,
                                        'latitude': lat,
                                        'longitude': lng,
                                        'location_source': location_source})
        offers = []

    paginator = Paginator(offers, OFFERS_PER_PAGE)
    page = paginator.page(request.GET.get('page', 1))
    saved_filters = SavedFilter.objects.filter(owner=userprofile)
    return render_to_response_context(request,
                                      'offers/browse_offers.html',
                                      {'form': form,
                                       'page': page,
                                       'saved_filters':saved_filters})
开发者ID:Joeboy,项目名称:django-sharestuff,代码行数:52,代码来源:views.py

示例4: home

# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import lat_lon [as 别名]
def home(request):
    _dict = {}
    g = GeoIP()
    #    lat, lng = g.lat_lon(get_client_ip(request))
    lat, lng = g.lat_lon("108.34.252.180")
    _dict["lat"] = lat
    _dict["lng"] = lng
    point = Point(x=lng, y=lat, srid=4326)

    nearby_courses = Course.objects.distance(point).order_by("distance")[:15]
    _dict["nearby_courses"] = nearby_courses
    nearby_courses_coords = [{"lat": c.location.y, "lng": c.location.x} for c in nearby_courses]
    _dict["nearby_courses_coords"] = simplejson.dumps(nearby_courses_coords)

    return render_to_response("home.html", _dict, context_instance=RequestContext(request))
开发者ID:dustinmm80,项目名称:discgolf,代码行数:17,代码来源:views.py

示例5: lat_lon

# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import lat_lon [as 别名]
 def lat_lon(self):
     """
     this method returns lat, lon if avail.
     OR it sets lat and lon from GeoIP
     and then returns them
     """
     if self.lat and self.lon:
         return self.lat, self.lon
     else:
         g = GeoIP()
         ret = g.lat_lon(self.ip)
         if ret:
             lat, lon = ret
             self.lat = lat
             self.lon = lon
             self.save()
             return self.lat, self.lon
         else:
             return None
开发者ID:krsanky,项目名称:django-site-stats,代码行数:21,代码来源:models.py

示例6: get_locale_from_ip

# 需要导入模块: from django.contrib.gis.utils import GeoIP [as 别名]
# 或者: from django.contrib.gis.utils.GeoIP import lat_lon [as 别名]
def get_locale_from_ip(ip_address):
    g = GeoIP()
    lat, lon = g.lat_lon('38.108.107.34')
    return lat, lon
开发者ID:IanWhalen,项目名称:weather_app,代码行数:6,代码来源:geo_handler.py


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