All Integrations

Mapbox: Geolocation

Geolocation
Author
Ian Jennings
Last Updated
2016-08-03
Mapbox: Geolocation

Walkthrough

Whenever a client publishes to the PubNub network, it's IP is added as a meta value to the request packet and is available in a block under request.client.ip. Then the IP's location is estimated using the free ip-api.com API. It's super simple, all we need to do is make a request to http://ip-api.com/json/[ip]

The ip-api.com service will respond with an estimated geolocation, city, state, country, as well as information about the internet service provider (ISP). Here's an example of a response from the service:

type: embedded-entry-inline id: qxv62wUCGncz0O56Bp1bx

Now if you subscribe to eon-map-geolocation-output using the same keys supplied into the block, you'll see the EON formatted output ready to be plotted.

Input

This block can take any payload as input, the contents do not matter as the IP is taken from the message's meta properties.

Output

The block publishes information about the client's location onto an output channel.

Mapbox's IP-to-Geolocation API plots a user's location on a map based on their IP address, without having to ask the client for the geolocation data.

The Mapbox geolocation block allows you to plot user or device location, and move that marker based on changes in location, in real time. In streaming coordinates, any number of subscribers can watch changes in geolocation on the live-updating map.