Permalink
Browse files

Merge branch 'master' of github.com:igorsobreira/wifimap

  • Loading branch information...
2 parents 47b6fae + ee54b22 commit 08071e227fe74e383a7d50afa8a8abc0f71a5484 @igorsobreira committed Aug 15, 2010
@@ -20,7 +20,11 @@ var Map = {
this.markers = [];
-
+ /*
+ google.maps.event.addListener(Map.map, 'dragend', function() {
+ SpotManager.listSpots();
+ });
+ */
},
followCenter: function(callback) {
@@ -97,7 +97,7 @@ var AddSpotPage = {
var SpotListPage = {
load: function() {
- SpotManager.listSpots();
+ SpotManager.setCenter();
},
unload: function() {
Map.removeAllMarkers();
@@ -1,9 +1,6 @@
var SpotManager = {
init: function () {
-
- //default center location
- $('#search-form input[type=text]').val('Rio de Janeiro, Brazil');
-
+
this.bindSearchSubmit();
// this should go to #/spots/add load callback
@@ -37,29 +34,64 @@ var SpotManager = {
}
});
},
-
+ /*
setCenter: function(data) {
+
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
if (is_chrome) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position){
var initialLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
Map.map.setCenter(initialLocation);
- SpotManager.afterCentralize(data.points);
+ SpotManager.afterCentralize(data);
}, function() {
Map.map.setCenter(new google.maps.LatLng(data.center_point[1][0], data.center_point[1][1]));
- SpotManager.afterCentralize(data.points);
+ SpotManager.afterCentralize(data);
});
} else {
Map.map.setCenter(new google.maps.LatLng(data.center_point[1][0], data.center_point[1][1]));
- SpotManager.afterCentralize(data.points);
+ SpotManager.afterCentralize(data);
}
} else {
Map.map.setCenter(new google.maps.LatLng(data.center_point[1][0], data.center_point[1][1]));
- SpotManager.afterCentralize(data.points);
+ SpotManager.afterCentralize(data);
}
+ },*/
+
+ getPointByIp: function(callback) {
+ $.ajax({
+ url: '/spots/point_by_ip/',
+ method: 'GET',
+ dataType: 'json',
+ success: function(data){
+ Map.map.setCenter(new google.maps.LatLng(data[1][0], data[1][1]));
+ }
+ });
+ },
+
+ setCenter: function(point) {
+
+ if (point == null) {
+
+ var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
+
+ if (is_chrome) {
+ if (navigator.geolocation) {
+ navigator.geolocation.getCurrentPosition(function(position){
+ point = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
+ Map.map.setCenter(point);
+ }, function() {
+ SpotManager.getPointByIp();
+ });
+ } else {
+ SpotManager.getPointByIp();
+ }
+ } else {
+ SpotManager.getPointByIp();
+ }
+ }
},
listSpots: function() {
@@ -73,9 +105,12 @@ var SpotManager = {
});
},
- afterCentralize: function(points) {
+ afterCentralize: function(data) {
+
+ $('#search-form input[type=text]').val(data.center_point[0]);
+
SpotManager.getAccessPointsListByBounds();
- SpotManager.addSpotsToMap(points);
+ SpotManager.addSpotsToMap(data.points);
},
bindSearchSubmit: function() {
@@ -1,8 +1,14 @@
from django.test import TestCase
+from django.core.urlresolvers import reverse
+from django.utils import simplejson
+from django.conf import settings
from spots.lib import point_by_ip
class PointByIpTest(TestCase):
+
+ def setUp(self):
+ settings.DEBUG = True
def test_point_by_ip(self):
point = point_by_ip('201.7.176.59')
@@ -14,4 +20,8 @@ def test_point_by_ip_with_city(self):
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]]
+ assert point == ['Brea, CA, USA', [33.916680499999998, -117.9000604]]
+
+ def test_view_point_by_ip(self):
+ response = self.client.get(reverse('point_by_ip'))
+ assert simplejson.loads(response.content) == [u'Sao Paulo - S\xe3o Paulo, Brazil', [-23.548943300000001, -46.638818200000003]]
@@ -141,4 +141,14 @@ def vote(request, id):
}
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")
+
View
@@ -18,6 +18,8 @@
url(r'^spots/search/$', 'spots.views.search_spots', name='spots_search'),
url(r'^spots/list/$', 'spots.views.list_spots', name='spots_list'),
+ url(r'^spots/point_by_ip/$', 'spots.views.get_point_by_ip', name='point_by_ip'),
+
)
if settings.DEBUG:

0 comments on commit 08071e2

Please sign in to comment.