Changeset 02e3694


Ignore:
Timestamp:
11/14/10 03:58:36 (3 years ago)
Author:
xkolman2 <xkolman2@…>
Branches:
master
Children:
102aa48
Parents:
cb42f66
git-author:
xkolman2 <xkolman2@…> (11/14/10 03:58:36)
git-committer:
xkolman2 <xkolman2@…> (11/14/10 03:58:36)
Message:

previous commit actually also added setting urrent position on POI coordinates
add asynchronous address routing
assure the screen is properly refreshed if something important for asynchronous road lookup happens

git-svn-id: https://nlp.fi.muni.cz/svn/gps_navigace/trunk@221 0858a4d0-ffff-46e5-938e-62b5ecb34222

Location:
modules
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • modules/mod_onlineServices.py

    rcb42f66 r02e3694  
    122122    local = self.googleLocalQuery(queryWithLL) 
    123123    return local 
    124  
    125  
    126  
     124   
    127125  def googleDirectionsAsync(self, start, destination, outputHandler, key): 
    128126    """a background running googledirections query 
    129        outputHandler will be proided with the results + the specified key string""" 
     127       -> verbatim start and destination will be used in route descritpion, no geocoding 
     128       outputHandler will be provided with the results + the specified key string""" 
     129    self.routingThread = self.Worker(self, "onlineRoute", (start, destination), outputHandler, key) 
     130    self.routingThread.daemon = True 
     131    self.routingThread.start() 
     132     
     133  def googleDirectionsLLAsync(self, start, destination, outputHandler, key): 
     134    """a background running googledirections query 
     135    - Lat Lon pairsversion -> for geocoding the start/destination points (NOT first/last route points) 
     136       outputHandler will be provided with the results + the specified key string""" 
    130137    self.routingThread = self.Worker(self, "onlineRouteLL", (start, destination), outputHandler, key) 
    131138    self.routingThread.daemon = True 
     
    164171 
    165172      try: 
     173        print start, destination 
    166174        directions = gmap.directions(start, destination, dir) 
    167175      except: 
     
    169177        try: 
    170178          directions = gmap.directions(start, destination) 
    171         except Exception, e: 
    172           if e.status == 604: 
    173             print "onlineServices:Gdirections:ruting failed -> no route found" % e 
    174             self.sendMessage("ml:notification:m:No route found;3") 
     179        except googlemaps.googlemaps.GoogleMapsError, e: 
     180          if e.status == 602: 
     181            print "onlineServices:Gdirections:routing failed -> address not found" % e 
     182            self.sendMessage("ml:notification:m:Address(es) not found;5") 
     183          elif e.status == 604: 
     184            print "onlineServices:Gdirections:routing failed -> no route found" % e 
     185            self.sendMessage("ml:notification:m:No route found;5") 
    175186          else: 
    176187            print "onlineServices:Gdirections:ruting failed with exception:\n%s" % e 
    177188 
    178189          directions = [] 
     190          self.set('needRedraw', True) 
    179191 
    180192    else: 
     
    256268          directions = self.getOnlineRoute(start,destination) 
    257269 
    258           if type == "onlineRouteLL": 
     270          if self.type == "onlineRouteLL": 
    259271            # reverse geocode the start and destination coordinates (for the info menu) 
    260272            (fromLat,fromLon) = start 
    261273            (toLat,toLon) = destination 
    262             self.setStatusMessage("geocoding start") 
     274            self.setStatusMessage("geocoding start...") 
    263275            startAddress = self.reverseGeocode(fromLat,fromLon) 
    264             self.setStatusMessage("geocoding destination") 
     276            self.setStatusMessage("geocoding destination...") 
    265277            destinationAddress = self.reverseGeocode(toLat,toLon) 
    266278          else: 
    267             startAddress = "start address unknown" 
    268             destinationAddress = "destination address unknown" 
     279            startAddress = start 
     280            destinationAddress = destination 
    269281          self.setStatusMessage("online routing done") 
    270282          # send the results to the output handler 
  • modules/mod_route.py

    rcb42f66 r02e3694  
    205205              traceback.print_exc(file=sys.stdout) 
    206206              self.sendMessage('ml:notification:m:No route found;3') 
     207              self.set('needRedraw', True) 
    207208            if "show" in args: 
    208209              """switch to map view and go to start/destination, if requested""" 
     
    306307    online = self.m.get('onlineServices', None) 
    307308    if online: 
    308 #    directions = online.googleDirectionsLL(fromLat, fromLon, toLat, toLon) 
    309       online.googleDirectionsAsync((fromLat, fromLon), (toLat, toLon), self.handleRoute, "onlineRoute") 
     309      online.googleDirectionsLLAsync((fromLat, fromLon), (toLat, toLon), self.handleRoute, "onlineRoute") 
     310       
     311  def doAddressRoute(self, start, destination): 
     312    """Route from one point to another, and set that as the active route""" 
     313    online = self.m.get('onlineServices', None) 
     314    if online: 
     315      print "routing from %s to %s" % (start,destination) 
     316      online.googleDirectionsAsync(start, destination, self.handleRoute, "onlineRouteAdress2Adress") 
    310317 
    311318  def handleRoute(self, key, resultsTupple): 
     
    316323        # remove any possible prev. route description, so new a new one for this route is created 
    317324        self.text = None 
    318         if directions: # is there actually something in th directions ? 
     325        if directions: # is there actually something in the directions ? 
    319326          polyline = directions['Directions']['Polyline']['points'] # the route is encoded as a polyline 
    320327          route = self.decode_line(polyline) # we decode the polyline to a list of points 
    321328          self.processAndSaveResults(route, directions, startAddress, destinationAddress) 
    322  
    323   def doAddressRoute(self, start, destination): 
    324     """Route from one point to another, and set that as the active route""" 
    325     online = self.m.get('onlineServices', None) 
    326     if online == None: 
    327       return 
    328     print "routing from %s to %s" % (start,destination) 
    329     directions = None 
    330     try: 
    331       directions = online.googleDirections(start, destination) 
    332     except googlemaps.googlemaps.GoogleMapsError, e: 
    333       if e.status == 602: # address/addresses not found 
    334         print "address not found" 
    335         self.sendMessage('notification:adress(es) not found#5') 
    336  
    337     if directions == None: 
    338       return 
    339  
    340     # remove any possible prev. route description, so new a new one for this route is created 
    341     self.text = None 
    342  
    343     polyline = directions['Directions']['Polyline']['points'] # the route is encoded as a polyline 
    344     route = self.decode_line(polyline) # we decode the polyline to a list of points 
    345     # handle the results 
    346     if len(route) >= 2: 
    347       start = (route[0]) 
    348       destination = (route[-1]) 
    349     self.processAndSaveResults(route, directions, start, destination) 
     329    elif key == "onlineRouteAdress2Adress": 
     330      if len(resultsTupple) == 3: 
     331        (directions, startAddress, destinationAddress) = resultsTupple 
     332        # remove any possible prev. route description, so new a new one for this route is created 
     333        self.text = None 
     334        if directions: # is there actually something in the directions ? 
     335          polyline = directions['Directions']['Polyline']['points'] # the route is encoded as a polyline 
     336          route = self.decode_line(polyline) # we decode the polyline to a list of points 
     337          self.processAndSaveResults(route, directions, startAddress, destinationAddress) 
     338    self.set('needRedraw', True) 
    350339     
    351340  def processAndSaveResults(self, route, directions, startAddress, destinationAddress): 
Note: See TracChangeset for help on using the changeset viewer.