Esempio n. 1
0
    def from_location(cls, geocaching, location):
        """Return a :class:`.Point` instance from geocoded location.

        :param .Geocaching geocaching: Reference to :class:`.Geocaching` instance, used to do
            a geocoding request.
        :param str location: Location to geocode.
        :raise .GeocodeError: If location cannot be geocoded (not found).
        """
        res = geocaching._request("api/geocode", params={"q": location}, expect="json")

        if res["status"] != "success":
            raise GeocodeError(res["msg"])

        return cls(float(res["data"]["lat"]), float(res["data"]["lng"]))
Esempio n. 2
0
    def geocode(self, query):
        """Tries to fetch coordinates for given query."""

        assert type(query) is str

        url = self._urls["geocode"] + "?q=" + query
        try:
            res = self._browser.get(url).json()
        except requests.exceptions.ConnectionError as e:
            raise Error("Cannot load geocode page.") from e

        if res["status"] != "success":
            raise GeocodeError(res["msg"])

        return Point(float(res["data"]["lat"]), float(res["data"]["lng"]))