예제 #1
0
 def row_to_entity(row):
     spot_entity = Spot()
     spot_entity.id = row.id
     spot_entity.name = row.name
     spot_entity.position = GeoPoint.row_to_object(row.position)
     spot_entity.tags = row.tags
     spot_entity.tracks_current = [Track.row_to_object(track_row) for track_row in row.tracks_current]
     spot_entity.tracks_old = [Track.row_to_object(track_row) for track_row in row.tracks_old]
     return spot_entity
예제 #2
0
    def google_geocode_service(self, address):
        """ Method to access the geocoding service by Google
            address: (string) Address for which latitude longitudes are required. Must be space separated

            Returns: None or GeoPoint with the latitude, longitude and full address
        """
        if self.google_api_key is None:
            logger.error('Are you sure google api credentials are set?')
            return None
        address = "?address=" + address
        app_key = "&key=" + self.google_api_key
        request_url = _GOOGLE_BASE_URL + address + app_key
        api_response = self.request(url=request_url)
        if api_response is None:
            return None
        if get_config(api_response, self._GOOGLE_STATUS_CONFIG) == "OK":
            lat_long = get_config(api_response, self._GOOGLE_LAT_LONG_CONFIG)
            addr = get_config(api_response, self._GOOGLE_ADDR_CONFIG)
            pt = GeoPoint(latitude=lat_long['lat'], longitude=lat_long['lng'], address=addr)
            return pt
        logger.error('Bad request for google API, status received: ' + get_config(api_response, self._GOOGLE_STATUS_CONFIG))
        return None
예제 #3
0
    def here_geocode_service(self, address):
        """ Method to access the geocoding service by HERE
            address: (string) Address for which latitude longitudes are required. Must be space separated

            Returns: None or GeoPoint with the latitude, longitude and full address
        """
        if self.here_app_id is None or self.here_app_code is None:
            logger.error('Are you sure here app credentials are set?')
            return None
        app_id = "?app_id=" + self.here_app_id
        app_code = "&app_code=" + self.here_app_code
        address = "&searchtext=" + address
        request_url = _HERE_BASE_URL + app_id + app_code + address
        api_response = self.request(url=request_url)
        if api_response is None:
            return None
        if get_config(api_response, self._HERE_STATUS_CONFIG):
            lat_long = get_config(api_response, self._HERE_LAT_LONG_CONFIG)
            addr = get_config(api_response, self._HERE_ADDR_CONFIG)
            pt = GeoPoint(latitude=lat_long['Latitude'], longitude=lat_long['Longitude'], address=addr)
            return pt
        logger.error('Bad request, no data received')
        return None
예제 #4
0
 def row_to_object(row):
     checkpoint = Checkpoint()
     checkpoint.id = row.id
     checkpoint.location = GeoPoint.row_to_object(row.location)
     return checkpoint