This is based on the work by many others.
Firstly, pyicloud – https://github.com/picklepete/pyicloud
For this you need:
sudo apt-get install python-pip
sudo apt-get install python-dev libffi-dev
sudo pip install pyopenssl ndg-httpsclient pyasn1
sudo pip install pyicloud
As the pyicloud documentation mentions, the first time you use this you will get a message from Apple letting you know your iCloud account was accessed.
To test I created location.py :
from pyicloud import PyiCloudService
api = PyiCloudService('myaccount@icloud.com','password')
print(api.devices)
print(api.devices[1])
print(api.devices[1].location())
python location.py
The second part of this is iphone-locator-bridge
I modified this a bit for my specific site. The includes changing the openhab items defined, passing back the actual longitude/latitude and distance and only running on demand.
I found the POST syntax in the original was giving me issues so I converted to the GET syntax:
url = '%s/CMD?%s=%s' % (gConfigurationOH['ohserver'], gConfigurationOH['ohitemdist'], dist)
It was necessary to add complete path info for the log file and the config file in roder for these to be found correctly when the script is called by an Openhab executeCommandLine().
The iPhone and home locations are then plotted on Google Maps using the info found at https://github.com/openhab/openhab/wiki/GoogleMap.