""" LifeFlow AI - Core Helpers 純資料處理工具,無 UI 依賴 """ def decode_polyline(polyline_str): """ 解碼 Google Maps Polyline 字符串為 (lat, lng) 列表 純 Python 實現,無需額外依賴 """ index, lat, lng = 0, 0, 0 coordinates = [] changes = {'latitude': 0, 'longitude': 0} while index < len(polyline_str): for unit in ['latitude', 'longitude']: shift, result = 0, 0 while True: byte = ord(polyline_str[index]) - 63 index += 1 result |= (byte & 0x1f) << shift shift += 5 if not byte >= 0x20: break if (result & 1): changes[unit] = ~(result >> 1) else: changes[unit] = (result >> 1) lat += changes['latitude'] lng += changes['longitude'] coordinates.append((lat / 100000.0, lng / 100000.0)) return coordinates