Integrating Mapbox SDK in Unity for Seamless Map Integration
Software Engineering

Integrating Mapbox SDK in Unity for Seamless Map Integration

Expert App Devs
Expert App Devs
4 min read

Introduction

This blog is about implementing the Mapbox SDK for the Unity project. This is a step-by-step guideline for Unity developers to integrate Mapbox SDK into games.

How the Mapbox Maps SDK works

The Mapbox Maps SDK for Unity is designed to help Unity developers add dynamic map data to their games and applications by providing a straightforward programmatic and graphical interface to Mapbox's web services APIs

How to Start

To install the latest Mapbox SDK click hereCreate a new project in the Unity editor




For importing Mapbox SDK select Assets > Import Package > Custom Package… Navigate to the directory where you downloaded the latest SDK and select it

Import selected assets in the package

Set Access Token

Create an account using this linkCopy your access token

Setup access token in unity

Past your access token and click on Submit button to check if it is valid or not

Now we are all set to integrate different types of map gamesLocation Based GameThe location-based shows how to position and orient a Player GameObject on a map using a GPS device or using the editor directlyThere are two location-based game example scenes inside of the SDK: Location-based game and Astronaut gameBoth scenes use the LocationProvider. Which will automatically use the device's GPS to position the game mapTo use LocationProvider we just need to drag and drop the LocationBasedGame prefab game object into the scene

The LocationProvider game object shows the player’s location, either in the real world or in the unity simulator. Without LocaionProvider scripts location would be hard coded in the AbstractMap scriptDeviceLocationProvider: It uses GPS data on the device. The player game object follows the location on the map which is provided by the GPS device updateEditorLocationProvider: It is similar to DeviceLocationProvider, but its works in the editorLocationArrayEditorLocationProvider: It allows the player game object to move across a set of points entered as latitude and longitude coordinates in an arrayTransformaLocationProvider: It helps the player game object to follow the position and rotation of other game objectsDeviceLocationProviderAndroidNative: It uses the GPS data to optimize for Android devicesUsing the Location based game example, we can create a pannable, zoomable map that a player can move around on it

Customize map

Create a map of New York, USASelect the Map object at the inspector window. Under the AbstractMap general settings, either change the location to 40.7306, -73.9866 or search “New York”Enable Preview so we can see current changes in the game scene

Now open the Image settings and change the Data Source to “Mapbox Satellite Street”Now open the Terrain settings and change the Elevation Layer Type to “Flat Terrain



It looks like this in the game scene


Open the MAP LAYERS settings and change the Data source to “Mapbox Streets”Open the Features setting and click on Add Feature button and select Buildings

There are several options to customize the building module


You can modify this value according to your need


Save and hit Play to see the “New York” map

If you have any questions regarding Unity Game Development Services Connect with us today!

Discussion (0 comments)

0 comments

No comments yet. Be the first!