在emacs中使用google map api?!

当别人告诉你emacs 能做什么什么的时候,要淡定,这是emacsen固有的zhuangbility行为。

 

所以当区区在slashdot上看到google-maps-el 时,作为programmer,想到的只是仔细考察一下其实现过程:

It fully implements the Google Static Maps API and the Google Maps Geocoding API .

 

大约花了一下午,掌握了这两个api的使用之后,我改写了其中的一些函数:

;;;###autoload (defun jr-google-maps-geocode-location (location) (let* ((req (google-maps-geocode-request :address location)) (status (google-maps-geocode-request->status req))) (unless (eq status 'ok) (error (format "Unable to geocode %s: %s" location status))) (setq location (list (assoc 'formatted_address (google-maps-geocode-results->one-result (google-maps-geocode-request->results req))) (assoc 'location (cdr (assoc 'geometry (google-maps-geocode-results->one-result (google-maps-geocode-request->results req))))))))) ;;;###autoload (defun jr-google-maps (location &optional no-geocoding) "Run Google Maps on LOCATION. If NO-GEOCODING is t, then does not try to geocode the address and do not ask the user for a more precise location." (interactive (list (if (use-region-p) (buffer-substring-no-properties (region-beginning) (region-end)) (read-string "Location: ")))) (let* ((location (if no-geocoding location (jr-google-maps-geocode-location location))) (lat (cdr (assoc 'lat (assoc 'location location)))) (lng (cdr (assoc 'lng (assoc 'location location)))) ) (google-maps-static-show :markers `(((,(cdr (assoc 'formatted_address location))))) :zoom 14 :center (format "%f,%f" lat lng ) :lat lat :lng lng :format 'jpg))) (defun google-maps-static-up () "Move a Google map up." (interactive) (unless (and (plist-member google-maps-static-params :lat) (plist-member google-maps-static-params :lng) ) (error "No Current Lat&Lng")) (let* ((plist google-maps-static-params) (lat (plist-get plist :lat)) (lng (plist-get plist :lng)) (lvl (plist-get plist :zoom)) (new-lat (+ lat (offset-of-level lvl))) (new-center (format "%f,%f" new-lat lng ))) (plist-put plist :lat new-lat) (plist-put plist :center new-center) (apply 'google-maps-static-show plist)))

通过这两个变更,就在emacs可以支持方向键移动交互查看google map了,当然,由于基于static api,速度不是非常理想。不过通过这个实验,可以体验到很多google api和emacs编程。

 

CSDN的博客完全放elisp代码很不方便,如果有朋友对这个带方向移动交互的代码patch感兴趣,可以留言联系,或者自己研究一下(more fun)。下面是一张运行效果图:

在emacs中使用google map api?!_第1张图片

 

国人也有高手跟进了,并且提供了中文资料 。

 

另外说一下的是,google-maps-el的作者真是个高手啊,他的rainbow-mode和awesome X管理器非常好用,猛击 了解吧。

你可能感兴趣的:(api,list,Google,emacs,patch,fun)