|
@@ -10,14 +10,16 @@
|
|
|
(in-package #:timeliner.locations)
|
|
(in-package #:timeliner.locations)
|
|
|
|
|
|
|
|
(defparameter *google-kml-url* "https://www.google.com/maps/timeline/kml")
|
|
(defparameter *google-kml-url* "https://www.google.com/maps/timeline/kml")
|
|
|
|
|
+(defvar *mapquest-api-key* nil "ApiKey for mapquest API")
|
|
|
|
|
|
|
|
(defun reverse-geocode (lat lon)
|
|
(defun reverse-geocode (lat lon)
|
|
|
(let* ((data (yason:parse
|
|
(let* ((data (yason:parse
|
|
|
(flexi-streams:octets-to-string
|
|
(flexi-streams:octets-to-string
|
|
|
(drakma:http-request
|
|
(drakma:http-request
|
|
|
(format nil
|
|
(format nil
|
|
|
- "http://open.mapquestapi.com/nominatim/v1/reverse.php?format=json&lat=~F&lon=~F"
|
|
|
|
|
- lat lon)))))
|
|
|
|
|
|
|
+ "http://open.mapquestapi.com/nominatim/v1/reverse.php?format=json&key=~A&lat=~F&lon=~F"
|
|
|
|
|
+ *mapquest-api-key* lat lon) :force-binary t)
|
|
|
|
|
+ :external-format :utf-8)))
|
|
|
(address (gethash "address" data)))
|
|
(address (gethash "address" data)))
|
|
|
(values (gethash "display_name" data)
|
|
(values (gethash "display_name" data)
|
|
|
address)))
|
|
address)))
|
|
@@ -29,12 +31,14 @@
|
|
|
(let* ((point (cdr loc))
|
|
(let* ((point (cdr loc))
|
|
|
(lat (geo:latitude-deg point))
|
|
(lat (geo:latitude-deg point))
|
|
|
(lon (geo:longitude-deg point)))
|
|
(lon (geo:longitude-deg point)))
|
|
|
- (multiple-value-bind (text address) (reverse-geocode lat lon)
|
|
|
|
|
|
|
+ (multiple-value-bind (text address)
|
|
|
|
|
+ (handler-case (reverse-geocode lat lon)
|
|
|
|
|
+ (error () (values (format nil "Unknown at ~,2F, ~,2F" lat lon) nil)))
|
|
|
(kv
|
|
(kv
|
|
|
(kv :ts (car loc))
|
|
(kv :ts (car loc))
|
|
|
(kv :type "place")
|
|
(kv :type "place")
|
|
|
(kv :title text)
|
|
(kv :title text)
|
|
|
- (kv :language (gethash "country_code" address))
|
|
|
|
|
|
|
+ (kv :language (and address (gethash "country_code" address)))
|
|
|
(kv :loc (kv (kv :type "Point") ; GeoJSON Point
|
|
(kv :loc (kv (kv :type "Point") ; GeoJSON Point
|
|
|
(kv :coordinates (list lon lat))))))))
|
|
(kv :coordinates (list lon lat))))))))
|
|
|
|
|
|