DZone
Big Data Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Big Data Zone > Mapbox's API to Geocode and Search Location Information

Mapbox's API to Geocode and Search Location Information

This article looks at using geocoding API for big data.

Adetola Adewodu user avatar by
Adetola Adewodu
·
Jul. 19, 16 · Big Data Zone · Tutorial
Like (3)
Save
Tweet
4.63K Views

Join the DZone community and get the full member experience.

Join For Free

When starting the National Geographic project, the dataset used had missing data. The dataset was missing street, city, state or zipcode to go along with the longitude and latitude for parks. Also, when doing a general search of street, city, state or zipcode, we wanted the capability to get the longitude and latitude of the search term to supply the nearest parks. So I looked into using the Mapbox Geocoding API to solve the issues. This API allows users to easily change location text into graphic coordinates (Maryland → -76.349,38.841) by forward geocoding. Reverse geocoding is the opposite wherein a pair of coordinates, latitude and longitude, are converted into a particular name of a place(-110.547,44.596 →Yellowstone National Park).

Forward Geocoding

In forward geocoding, the query should be URL-coded, must not contain special characters such as semicolons that are often used to group or delimit requests. The response is usually made up of one or more results.

Here is what the URL looks like:

https://api.mapbox.com/geocoding/v5/mapbox.places/Query.json?access_token=<access token>

Here is an example use of the URL with the Query = Maryland:

https://api.mapbox.com/v4/geocode/mapbox.places/Maryland.json?access_token=<access token>

Here is sample of the response:

{"type":"FeatureCollection","query":["maryland"],"features":[{"id":"region.9113309487783240","type":"Feature","text":"Maryland","place_name":"Maryland, United States","relevance":0.99,"properties":{},"bbox":[-79.487651,37.886605,-74.8966568003481,39.722883],"center":[-76.349402,38.841628],"geometry":{"type":"Point","coordinates":[-76.349402,38.841628]}

To get the rest of the data, you will actually have to make the HTTP request in a browser or with a programming language. Also, with forward geocoding, country filtering and with proximity can be added. If you want more information about how to use the API to forward geocode, you can go here.

Reverse Geocoding

Reverse geocoding latitude and longitude coordinates as input. The response includes one result from each geocoding dataset.

Here is what the URL looks like:

https://api.mapbox.com/v4/geocode/mapbox.places/'+ xCoordinate+ ',' + yCoordinate + '.json?access_token=<access token>

Here is an example use of the URL with the x-coordinate/longitude = -110.547 and y coordinate/latitude = 44.596:

https://api.mapbox.com/v4/geocode/mapbox.places/-110.547,44.596.json.json?access_token=<access token>

Here is sample of the response:

{"type":"FeatureCollection","query":[-110.547,44.596],"features":[{"id":"place.55914","type":"Feature","text":"Yellowstone National Park","place_name":"Yellowstone National Park, Wyoming, United States","relevance":1,"properties":{},"bbox":[-111.056889009999,44.1312909900081,-109.825486991003,45.0039050099999],"center":[-110.83,44.46],"geometry":{"type":"Point","coordinates":[-110.83,44.46]},"context":[{"id":"postcode.8237635196769770","text":"82190"},{"id":"region.10947505346724150","text":"Wyoming"},{"id":"country.5877825732302570","text":"United States","short_code":"us"}]}

To get the rest of the data, you will actually have to make the HTTP request in a browser or with a programming language. Limiting the input coordinates to, at most, 5 decimal places usually improves precision and performance of the reverse geocoding process. If you want more information about using the API to reverse geocode, you can go here.

Forward and reverse geocoding can be further enhanced by filtering to match more types. Features such as country, region, postcode, place, neighborhood, address and POI (places of interest) may be used. In the end, Mapbox’s API allowed us to geocode data to get location information.

API

Published at DZone with permission of Adetola Adewodu, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Testing Strategies for Microservices
  • Everything You Need to Know About Web Pentesting: A Complete Guide
  • Java Class Loading: Performance Impact
  • How API Management Can Ease Your Enterprise Cloud Migration

Comments

Big Data Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo