WiFiの情報を元に現在地点の緯度経度情報を取得するAppleScriptです。
実行前にWiFiがオンになっている必要があるので、WiFiの状態を確認して、WiFiがオフだったらオンにする処理が必要になります。
AppleScript名:現在地点の緯度経度情報を取得する v2 |
— Created 2015-03-04 by Takaaki Naganoya, Shane Stanley — Modified 2015-12-06 by Takaaki Naganoya use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "CoreLocation" property locationManager : missing value property curLatitude : 0 property curLongitude : 0 –Get Current Geo Location set {aLat, aLong} to getCurrentGeoLocation() of me on getCurrentGeoLocation() set locationManager to current application’s CLLocationManager’s alloc()’s init() set locE to locationManager’s locationServicesEnabled() if (locE as boolean) = true then locationManager’s setDelegate:me locationManager’s setDesiredAccuracy:(current application’s kCLLocationAccuracyNearestTenMeters) locationManager’s setDistanceFilter:500 locationManager’s startUpdatingLocation() else return false –error in init end if set hitF to false repeat 3000 times if {curLatitude, curLongitude} is not equal to {0, 0} then set hitF to true exit repeat end if delay ("0.0001" as real) end repeat if hitF = false then return {false, false} return {curLatitude, curLongitude} end getCurrentGeoLocation on locationManager:manager didUpdateLocations:locations set location to (locations’s lastObject()) set eventDate to (location’s timestamp()) set howRecent to (eventDate’s timeIntervalSinceNow()) set howRecent to howRecent as real set howRecent to absNum(howRecent) if howRecent < 15.0 then set alt to location’s altitude –>(NSNumber) 46.356517791748 set aSpeed to location’s speed –>(NSNumber) -1.0 set aCourse to location’s course –North:0, East:90, South:180, West:270 –> (NSNumber) -1.0 set theDescription to location’s |description|() –> (NSString) "<+35.xxxxx,+139.xxxxxx> +/- 65.00m (speed -1.00 mps / course -1.00) @ 2015/03/04 8時56分41秒 日本標準時" set anNSScanner to current application’s NSScanner’s scannerWithString:theDescription anNSScanner’s setCharactersToBeSkipped:(current application’s NSCharacterSet’s characterSetWithCharactersInString:"<,") set {theResult, aLat} to anNSScanner’s scanDouble:(reference) set {theResult, aLng} to anNSScanner’s scanDouble:(reference) copy {aLat, aLng} to {my curLatitude, my curLongitude} else locationManager’s stopUpdatingLocation() end if end locationManager:didUpdateLocations: on locationManager:anCLLocationManager didFailWithError:anNSError display dialog (anNSError’s localizedDescription() as text) end locationManager:didFailWithError: on absNum(aNum) if aNum > 0 then return aNum else return (aNum * -1) end if end absNum |