指定の緯度・経度情報の場所を4つの異なる表示倍率の地図でダイアログ表示するAppleScriptライブラリ+呼び出しサンプルです。
–> Download display location.scptd (To ~/Library/Script Libraries/)
サンプルScriptでは、指定のIPアドレスの位置情報をipinfo.io上で調べて表示しています。
本ライブラリは、掲載サンプルのように「display multiple map」コマンドを提供するもので、地図.appに頼らずにAppleScriptだけで簡単な地図表示UIを利用できるようにします。
AppleScript名:display location sample |
— – Created by: Takaaki Naganoya – Created on: 2019/08/25 — – Copyright © 2019 jp.piyomarusoft, All Rights Reserved — use AppleScript version "2.4" — Yosemite (10.10) or later use framework "Foundation" use framework "AppKit" use scripting additions use dispLoc : script "display location" property |NSURL| : a reference to current application’s |NSURL| property NSString : a reference to current application’s NSString property NSJSONSerialization : a reference to current application’s NSJSONSerialization property NSUTF8StringEncoding : a reference to current application’s NSUTF8StringEncoding set anIP to "193.228.57.200" set locList to getGeoLocationByIPinfo(anIP) of me display multiple map main message "侵略場所の表示" sub message "今回の地球侵略の目的地は、地球上の以下の場所になります" with location locList with size {900, 600} –http://ipinfo.io/developers on getGeoLocationByIPinfo(myIP) set aURL to "http://ipinfo.io/" & myIP set aRes to callRestGETAPIAndParseResults(aURL, 10) of me if aRes = missing value then error "Network Error" end if set aInfo to loc of aRes set aPos to offset of "," in aInfo set aLatitude to text 1 thru (aPos – 1) of aInfo set aLongitude to text (aPos + 1) thru -1 of aInfo return {aLatitude, aLongitude} end getGeoLocationByIPinfo on callRestGETAPIAndParseResults(reqURLStr as string, timeoutSec as integer) set tmpData to (do shell script "curl -X GET \"" & reqURLStr & "\"") set jsonString to NSString’s stringWithString:tmpData set jsonData to jsonString’s dataUsingEncoding:(NSUTF8StringEncoding) set aJsonDict to NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value) if aJsonDict = missing value then return false return (aJsonDict as record) end callRestGETAPIAndParseResults |
More from my site
(Visited 62 times, 1 visits today)