Mapbox: Geolocation

Plot location on a real-time, live-updating map

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.

Setup

  1. Login or Register to Admin Portal

  2. Select Functions

  3. Select your desired App and Keyset

  4. Select "Explore Templates" and proceed with selected integration.

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:

{
    "as":"AS36351 SoftLayer Technologies Inc.",
    "city":"San Francisco (Haight-Ashbury)",
    "country":"United States",
    "countryCode":"US",
    "isp":"SoftLayer Technologies",
    "lat":37.7714,
    "lon":-122.447,
    "org":"SoftLayer Technologies",
    "query":"169.53.82.164",
    "region":"",
    "regionName":"California",
    "status":"success",
    "timezone":"America/Los_Angeles",
    "zip":""
}

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.

1

Output

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

1

Talk to an expert