All Articles

OSX LocateMe

1. 前言

locateme是一个命令行工具,能够调用osx系统自带的apple定位服务来给出经纬数据。

Github:netj/LocateMe。下载站:iHarder.net LocateMe

Returns your computer’s location using Apple’s built-in geolocation services.

2. 安装

可以从下载站下载软件包之后解压并放到bin下面,当然更推荐使用brew安装:

$ brew update --verbose && brew install locateme --verbose
$ which locateme
/usr/local/bin/locateme

这还没完,接下来要先使用一次locateme,会报错:

$ locateme

2021-08-31 10:47:01.299 locateme[32912:640457] [error code] != kCLErrorLocationUnknown: Error Domain=kCLErrorDomain Code=1 "(null)"
2021-08-31 10:47:01.299 locateme[32912:640457] Error: Error Domain=kCLErrorDomain Code=1 "(null)"

然后打开系统偏好设置 > 安全性与隐私 > 定位服务,勾选LocateMe。然后再尝试使用,应该就OK了:

$ locateme

<+XX.23453090,+XXX.48293057> +/- 65.00m (speed -1.00 mps / course -1.00) @ 2021/8/28 中国标准时间 XX:XX:XX

3. 使用

$ locateme -h
USAGE: locateme [options]
Version: 0.2.1
Outputs your current location using Apple's geolocation services.
  -h          This help message
  -g          Generate a Google Map URL
  -l          Generate long, multiline format
  -f format   Generate a custom output with the following placeholders
     {LAT}    Latitude as a floating point number
     {LON}    Longitude as a floating point number
     {ALT}    Altitude in meters as a floating point number
     {SPD}    Speed in meters per second as a floating point number
     {DIR}    Direction in degrees from true north as a floating point number
     {HAC}    Horizontal accuracy in meters as a floating point number
     {VAC}    Vertical accuracy in meters as a floating point number
     {TIME}   Timestamp (with date) of the location fix
     {HOST}   Computer hostname

Examples:

 Command: locateme -f "lat={LAT},lon={LON}"
 Output : lat=12.34567,lon=98.76543

 Command: locateme -f "<lat>{LAT}</lat><lon>{LON}</lon><alt>{ALT}</alt>"
 Output : <lat>12.34567</lat><lon>98.76543</lon><alt>123</alt>

一般这样用:

$ locateme -f "{\"lat\":\"{LAT}\",\"lon\":\"{LON}\"}"

{"lat":"XX.234463","lon":"XXX.482957"}

EOF

Published 2021/10/2

Some tech & personal blog posts