1 import googlemaps as gmaps
2 from typing import Any, Dict, List, Tuple
7 def init(conf: Dict[str, Any]) -> None:
9 with open(conf["googlemaps"]["accesstoken"], encoding="ascii") as fl:
10 token = fl.read().rstrip()
11 gclient = gmaps.Client(key=token)
21 gsm_cells: List[Tuple[int, int, int]],
22 wifi_aps: List[Tuple[str, int]],
23 ) -> Tuple[float, float]:
24 assert gclient is not None
26 "home_mobile_country_code": mcc,
27 "home_mobile_network_code": mnc,
33 "locationAreaCode": loc,
35 "signalStrength": sig,
37 for loc, cellid, sig in gsm_cells
39 "wifi_access_points": [
40 {"macAddress": mac, "signalStrength": sig} for mac, sig in wifi_aps
43 result = gclient.geolocate(**kwargs)
44 if "location" in result:
45 return result["location"]["lat"], result["location"]["lng"]
47 raise ValueError("google geolocation: " + str(result))