The Geolocation service listens for commands on this object
Commands sent to the /pps/services/geolocation/control object are of the form:
msg::command_string\nid::ID_number\ndat:json:{JSON_data}
Responses always reflect the command_string and ID_number that were sent in the message, along with any errors:
res::command_string\nid::ID_number\ndat::json:{JSON_data}\nerr::error_description
The control object accepts these commands:
Command | Description |
---|---|
location | Query the current location based on the IP address. The format
for the dat field is as follows:
dat:json:{"period":2.0,"provider":"network","fix_type":"wifi"} where:
|
cancel | Cancel the currently running periodic request. |
As soon as the Geolocation service receives the location message from the client, it queries http://www.hostip.info to get the current location based on the IP address. The correctness of the result depends on the contents of the database that the hostip.info site provides. The absence of an IP address for the requesting client in the database might yield an arbitrary result (e.g., "wrong location").
Because the Geolocation service is multithreaded, it can handle requests from multiple clients at the same time.
Besides returning the client's message and ID, the Geolocation service can also send these responses:
Response | Description |
---|---|
accuracy | A percentage value representing the accuracy of the location (e.g., 60). |
latitude | The latitude (e.g., 45.3333). |
longitude | The longitude (e.g., -75.9). |
# exec 3<> /pps/services/geolocation/control?wait &&
echo 'msg::location\nid::test_1\ndat:json:{"period":5.0,"provider":"network","fix_type":"wifi"}' >&3 && cat <&3
The control object might now look like this:
@control res::location id::test_1 dat:json:{"accuracy":60,"latitude":45.3333,"longitude":-75.9}