def search_spots(request): json = {'points':[]} if request.GET.has_key('place'): geo_data = geocode(request.GET['place']) if geo_data['Status']['code'] == 200: address = geo_data['Placemark'][0]['address'] lng, lat = geo_data['Placemark'][0]['Point']['coordinates'][:2] json['center_point'] = [ address, [lat, lng] ] else: json['center_point'] = None else: if settings.DEBUG: json['center_point'] = point_by_ip('200.147.67.142') else: json['center_point'] = point_by_ip(request.META['REMOTE_ADDR']) points = AccessPoint.objects.all() for point in points: json['points'].append( {'id':point.id, 'point':[point.lat, point.lng]} ) return HttpResponse(simplejson.dumps(json), mimetype="application/json")
def get_point_by_ip(request): if settings.DEBUG: point = point_by_ip('200.147.67.142') else: point = point_by_ip(request.META['REMOTE_ADDR']) return HttpResponse(simplejson.dumps(point), mimetype="application/json")
def test_point_by_ip_with_city(self): point = point_by_ip('200.147.67.142') assert point == [u'Sao Paulo - S\xe3o Paulo, Brazil', [-23.548943300000001, -46.638818200000003]]
def test_point_by_ip_with_another_city(self): point = point_by_ip('208.113.199.25') assert point == ['Brea, CA, USA', [33.916680499999998, -117.9000604]]
def test_point_by_ip(self): point = point_by_ip('201.7.176.59') assert point == ["Brazil", [-14.235004, -51.925280000000001]]