Added method to retrieve GPS coordinates from tile
authorjaviplx <javiplx@gmail.com>
Fri, 4 Jun 2010 12:15:52 +0000 (12:15 +0000)
committerjaviplx <javiplx@gmail.com>
Fri, 4 Jun 2010 12:15:52 +0000 (12:15 +0000)
git-svn-id: file:///svnroot/wifihood/trunk/wifiscanner@12 c51dfc6a-5949-4919-9c8e-f207a149c383

wifiview

index 40a7a8c..4a6bbe8 100755 (executable)
--- a/wifiview
+++ b/wifiview
@@ -60,6 +60,13 @@ class mapWidget ( gtk.Image , WifihoodConfig ) :
     lat = lat * math.pi / 180
     return int( ( 1 - math.log( math.tan( lat ) + 1 / math.cos( lat ) ) / math.pi ) / 2 * 2 ** zoom )
 
+  def tilex2lon ( self , tilex , zoom ) :
+    return tilex / 2.0 ** zoom * 360.0 - 180.0
+
+  def tiley2lat ( self , tiley , zoom ) :
+    tiley = math.pi * ( 1 - 2 * tiley / 2.0 ** zoom )
+    return math.degrees( math.atan( math.sinh( tiley ) ) )
+
   def composeMap( self ) :
     center_x , center_y = self.win_x / 2 , self.win_y / 2
 
@@ -159,8 +166,8 @@ class mapWidget ( gtk.Image , WifihoodConfig ) :
 
   def SetZoom( self , zoom ) :
     self.hide()
-    # FIXME : Use current lat,lon instead of hardcoded ones
-    lat , lon = 40.40491 , -3.6774
+    lat = self.tiley2lat( self.reftile_y , self.zoom )
+    lon = self.tilex2lon( self.reftile_x , self.zoom )
     self.reftile_x , self.reftile_y = self.lon2tilex( lon , zoom ) , self.lat2tiley( lat , zoom )
     self.zoom = zoom
     self.refpix_x , self.refpix_y = 128 , 128