Skip to main content

Google Geolocation

Google's Geolocation API uses cell tower and Wi-Fi access point data to determine the latitude and longitude of a device. The API can easily be accessed via Pipelines using the webhook transformer.

The following example demonstrates using the Google Geolocation API to translate CBOR Wi-Fi access point data from a device network scan into a position for the device. The resolved position is delivered to LightDB Stream as a JSON payload. The json-patch transformer is leveraged to allow for using the same device payload as the HERE Positioning example to produce the same JSON output.

Example network scan data:

CBOR data displayed as JSON for documentation purposes only.

{
"wlan": [
{
"mac": "3c:37:86:5d:75:d4",
"rss": -35
},
{
"mac": "30:86:2d:c4:29:d0",
"rss": -35
},
{
"mac": "30:22:96:6B:9A:11",
"rss": -22
}
]
}

Example position result:

{
"location": {
"accuracy": 20,
"lat": 37.4241224,
"lng": -122.0915874
}
}
Reminder

Make sure to create a secret named GOOGLE_GEO_API_URL with the appropriate API key credentials.

filter:
path: "/netinfo"
content_type: application/cbor
steps:
- name: convert
transformer:
type: cbor-to-json
- name: transform-google-geo
transformer:
type: json-patch
parameters:
patch: |
[
{"op": "add", "path": "/wifiAccessPoints", "value": [{"macAddress": "", "signalStrength": 0}, {"macAddress": "", "signalStrength": 0}, {"macAddress": "", "signalStrength": 0}]},
{"op": "move", "from": "/wlan/0/mac", "path": "/wifiAccessPoints/0/macAddress"},
{"op": "move", "from": "/wlan/0/rss", "path": "/wifiAccessPoints/0/signalStrength"},
{"op": "move", "from": "/wlan/1/mac", "path": "/wifiAccessPoints/1/macAddress"},
{"op": "move", "from": "/wlan/1/rss", "path": "/wifiAccessPoints/1/signalStrength"},
{"op": "move", "from": "/wlan/2/mac", "path": "/wifiAccessPoints/2/macAddress"},
{"op": "move", "from": "/wlan/2/rss", "path": "/wifiAccessPoints/2/signalStrength"},
{"op": "remove", "path": "/wlan"}
]
- name: get-location
transformer:
type: webhook
parameters:
url: $GOOGLE_GEO_API_URL
- name: transform-standard-loc
transformer:
type: json-patch
parameters:
patch: |
[
{"op": "add", "path": "/location/accuracy", "value": 0},
{"op": "move", "from": "/accuracy", "path": "/location/accuracy"}
]
- name: send-lightdb
destination:
type: lightdb-stream
version: v1