> For the complete documentation index, see [llms.txt](https://docs.mapbox.com/help/ja/llms.txt)

# Switch from Google Maps JavaScript API to Mapbox GL JS

Are you using the **Google Maps JavaScript API** and want to switch to **Mapbox GL JS**? This tutorial walks you through the core mapping concepts side by side, showing you the Google Maps approach alongside the equivalent Mapbox GL JS implementation at each step.

In this tutorial, you will:

-   Import Mapbox GL JS in place of the Google Maps JavaScript API
-   Initialize a map using `mapboxgl.Map`
-   Add a marker and popup
-   Load GeoJSON data as a source and render it with layers
-   Add hover interactivity using `addInteraction()`
-   Customize the basemap colors using `config.basemap`
-   Add a location search box using Mapbox Search JS

## Prerequisites

This guide assumes familiarity with front-end web development (HTML, CSS, and JavaScript). Experience with the Google Maps JavaScript API is helpful but not required.

To complete this tutorial, you will need:

-   **A Mapbox access token**: Find yours on the [Access token page](https://console.mapbox.com/account/access-tokens/) of your Mapbox account.
-   **A code editor**: A program like [Visual Studio Code](https://code.visualstudio.com/).

## Import Mapbox GL JS

Your Google Maps implementation loads the Google Maps JavaScript API via a `<script>` tag. The first step is to swap that out for the Mapbox GL JS library and its CSS file.

Replace your Google Maps script tag with the Mapbox GL JS CDN imports:

```diff
- <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_GOOGLE_MAPS_API_KEY"></script>

+ <script src="https://api.mapbox.com/mapbox-gl-js/v3.25.0/mapbox-gl.js"></script>
+ <link href="https://api.mapbox.com/mapbox-gl-js/v3.25.0/mapbox-gl.css" rel="stylesheet" />
```

A full `index.html` boilerplate would look like this:

```html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Switch to Mapbox</title>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <script src="https://api.mapbox.com/mapbox-gl-js/v3.25.0/mapbox-gl.js"></script>
    <link
      href="https://api.mapbox.com/mapbox-gl-js/v3.25.0/mapbox-gl.css"
      rel="stylesheet"
    />
    <style>
      body { margin: 0; padding: 0; }
      #map { position: absolute; top: 0; bottom: 0; width: 100%; }
    </style>
  </head>
  <body>
    <div id="map"></div>
    <script>
      // Code from the next steps will go here.
    </script>
  </body>
</html>
```

The `<div id="map">` container serves the same purpose as the container element you pass to `google.maps.Map` — it's where the map will be rendered, and should be styled to give the map a size on the page.

With Mapbox GL JS imported and a map container in place, you're ready to initialize a map.

## Initialize a map

Both APIs initialize a map by passing a container element and configuration options, but differ in coordinate ordering, authentication, and how the map style is specified.

### Google Maps JavaScript API

With the Google Maps JavaScript API, you initialize a map by passing a container element and an options object to `google.maps.Map`:

```js
const map = new google.maps.Map(document.getElementById('map'), {
  center: { lat: 40.73713, lng: -73.99365 },
  zoom: 11,
  mapId: 'YOUR_MAP_ID'
});
```

![Google Maps JavaScript API map centered on New York City](https://docs.mapbox.com/help/ja/assets/ideal-img/tutorials--google-to-mapbox--google-step-1-initialize-map.5ee7f6b.480.png)

### Mapbox GL JS

Add the following code inside your `<script>` tag to initialize a Mapbox GL JS map:

```js
const map = new mapboxgl.Map({
  accessToken: 'YOUR_MAPBOX_ACCESS_TOKEN',
  container: 'map',
  style: 'mapbox://styles/mapbox/standard',
  center: [-73.99365, 40.73713], // [lng, lat]
  zoom: 11.5
});
```

A few key differences from Google Maps:

-   **Coordinate order**: Google Maps uses `{ lat, lng }` objects. Mapbox uses `[lng, lat]` arrays throughout its API — longitude first, latitude second.
-   **Access token**: Set `accessToken` to your own Mapbox access token to authenticate requests.
-   **Style URL**: The `style` option takes a [style URL](https://docs.mapbox.com/help/ja/glossary/style-url/). `mapbox://styles/mapbox/standard` loads the [Mapbox Standard](https://docs.mapbox.com/map-styles/standard/guides/) style, a modern default basemap that supports runtime color and theme customization (covered later in this tutorial). Try the [Standard Style Playground](https://docs.mapbox.com/playground/standard-style/) to explore the available configuration options and copy the resulting code snippet directly into your project. You can also use a custom style created in [Mapbox Studio](https://console.mapbox.com/studio/).

Save your file and open it in a browser to see your map.

With the map rendering, the next step is to add a marker to a specific location.

## Add a marker

Both APIs provide a marker class to place a pin at a specific coordinate. The main difference is that Mapbox GL JS uses a fluent API where methods can be chained, while Google Maps takes a single configuration object.

### Google Maps JavaScript API

The modern approach to adding a marker in the Google Maps JavaScript API is `AdvancedMarkerElement`:

```js
const { AdvancedMarkerElement } = google.maps.marker;

const marker = new AdvancedMarkerElement({
  map: map,
  position: { lat: 40.7484, lng: -73.9857 },
  title: 'Empire State Building'
});
```

![Google Maps JavaScript API with a marker at the Empire State Building](https://docs.mapbox.com/help/ja/assets/ideal-img/tutorials--google-to-mapbox--google-step-2-add-marker.b78c8bf.480.png)

### Mapbox GL JS

In Mapbox GL JS, use the [`Marker`](https://docs.mapbox.com/mapbox-gl-js/api/markers/#marker) class with a fluent API. You create a marker, set its coordinates, and add it to the map in separate steps.

Add the following code after your map initialization:

```js
const marker = new mapboxgl.Marker()
  .setLngLat([-73.9857, 40.7484]) // [lng, lat]
  .addTo(map);
```

-   `setLngLat()` sets the marker position using longitude-first coordinates.
-   `addTo(map)` places the marker on the map.

Save and refresh to see a default blue pin at the Empire State Building.

Now that the marker is on the map, the next step is to attach a popup so users can interact with it.

> **Note: More ways to add markers**
> 
> The `Marker` class is ideal for adding a small number of interactive points with custom HTML content. You can also render markers by adding a GeoJSON source and a symbol layer, which is more efficient when you need to display large numbers of points. See the [Add your data](https://docs.mapbox.com/mapbox-gl-js/guides/add-your-data/) guide for an overview of the different approaches.

## Add a popup

Google Maps uses a separate `InfoWindow` class that you open manually via a click listener. Mapbox GL JS lets you attach a `Popup` directly to a marker, so no separate event handler is needed.

### Google Maps JavaScript API

The Google Maps JavaScript API uses `InfoWindow` for popups. You create the popup separately and open it in response to a click event on the marker:

```js
const infoWindow = new google.maps.InfoWindow({
  content: '<h3>Empire State Building</h3><p>Constructed in just 410 days!</p>'
});

marker.addListener('gmp-click', () => {
  infoWindow.open({ anchor: marker, map: map });
});
```

![Google Maps JavaScript API with an InfoWindow popup open at the Empire State Building](https://docs.mapbox.com/help/ja/assets/ideal-img/tutorials--google-to-mapbox--google-step-3-add-popup.fb81fab.480.png)

### Mapbox GL JS

In Mapbox GL JS, you attach a [`Popup`](https://docs.mapbox.com/mapbox-gl-js/api/markers/#popup) directly to a marker using `.setPopup()`. No separate click listener is needed — the popup opens automatically when the user clicks the marker.

Replace your marker declaration with the following:

```js
const popup = new mapboxgl.Popup({ offset: 25 })
  .setHTML('<h3>Empire State Building</h3><p>Constructed in just 410 days — and for 40 years it held the record as the world\'s tallest building.</p>');

const marker = new mapboxgl.Marker()
  .setLngLat([-73.9857, 40.7484])
  .setPopup(popup)
  .addTo(map);
marker.togglePopup();
```

-   `setHTML()` sets the popup's content as an HTML string.
-   `setPopup()` attaches the popup to the marker so it opens on click.
-   `togglePopup()` opens the popup immediately on load.

Save and refresh. The popup will be open by default, and can be closed and reopened by clicking the marker.

With the marker and popup in place, the next step is to add GeoJSON polygon data to the map.

## Add GeoJSON data

GeoJSON is the standard format for geographic data on the web, and GeoJSON sources are a developer-friendly way to add points, lines, and polygons directly to a Mapbox GL JS map. They work well for smaller supporting datasets — annotations, highlighted areas, routes, and similar features. For larger datasets that would be impractical to load as a static file, you can publish the data as a [tileset](https://docs.mapbox.com/studio-manual/reference/tilesets/) and reference it as a vector tile source instead.

In this step, you'll add two polygon features representing New York City neighborhoods.

> **Note: Loading GeoJSON from a URL**
> 
> In this example the GeoJSON is defined inline as a JavaScript object, but the `data` property of a GeoJSON source also accepts a URL pointing to an external `.geojson` file. This is useful when your data is hosted separately or updated independently of your code.

First, add the following GeoJSON object before your map initialization in your `<script>` tag:

```js
const neighborhoods = {
  type: 'FeatureCollection',
  features: [
    {
      type: 'Feature',
      properties: { name: 'Midtown' },
      geometry: {
        type: 'Polygon',
        coordinates: [[
          [-73.9950637, 40.7722064],
          [-73.9597323, 40.7592046],
          [-73.9721082, 40.7434781],
          [-73.9725075, 40.7348572],
          [-74.0094358, 40.7495272],
          [-74.0094358, 40.7533076],
          [-73.9992555, 40.7651011],
          [-73.9962613, 40.7684271],
          [-73.9950637, 40.7722064]
        ]]
      }
    },
    {
      type: 'Feature',
      properties: { name: 'Financial District' },
      geometry: {
        type: 'Polygon',
        coordinates: [[
          [-74.0157699, 40.7163373],
          [-74.0050355, 40.71292],
          [-73.9983801, 40.7072241],
          [-74.0097586, 40.7008767],
          [-74.0153406, 40.7003885],
          [-74.0183462, 40.7026671],
          [-74.0202784, 40.7051084],
          [-74.0157699, 40.7163373]
        ]]
      }
    }
  ]
};
```

Both APIs can render GeoJSON polygons on the map, but take different approaches. Google Maps uses a built-in Data layer with a single style applied to all features; Mapbox GL JS separates data from visualization using sources and layers, so fill and outline can be controlled independently.

### Google Maps JavaScript API

The Google Maps JavaScript API adds GeoJSON via the built-in Data layer:

```js
map.data.addGeoJson(neighborhoods);
map.data.setStyle({
  fillColor: '#3b82f6',
  fillOpacity: 0.35,
  strokeColor: '#1d4ed8',
  strokeWeight: 2
});
```

![Google Maps JavaScript API with blue polygon overlays for Midtown and Financial District](https://docs.mapbox.com/help/ja/assets/ideal-img/tutorials--google-to-mapbox--google-step-4-add-geojson.aef60a0.480.png)

### Mapbox GL JS

Mapbox GL JS separates **data** (sources) from **visualization** (layers). A source holds the data; one or more layers define how it is rendered. This separation gives you fine-grained control — for example, you can use the same source to render a fill and an outline independently.

Add the following code inside a `map.on('style.load', ...)` callback:

```js
map.on('style.load', () => {
  map.addSource('neighborhoods', {
    type: 'geojson',
    data: neighborhoods
  });

  map.addLayer({
    id: 'neighborhoods-fill',
    type: 'fill',
    source: 'neighborhoods',
    paint: {
      'fill-color': '#3b82f6',
      'fill-opacity': 0.35
    }
  });

  map.addLayer({
    id: 'neighborhoods-outline',
    type: 'line',
    source: 'neighborhoods',
    paint: {
      'line-color': '#1d4ed8',
      'line-width': 2
    }
  });
});
```

> **Note: Why wrap code in map.on('style.load', ...)?**
> 
> Sources and layers can only be added after the map style has finished loading. The `map.on('style.load', ...)` callback fires as soon as the style is processed and ready, without waiting for tiles or other map resources to finish loading — making it the recommended choice for adding sources and layers.

Save and refresh to see the neighborhood polygons on the map.

The polygons are visible, but static. Next, you'll add hover interactivity so users can identify each neighborhood.

## Add interactivity

In this step you will add hover interactivity so that mousing over a neighborhood polygon displays its name in a tooltip.

The tooltip itself is a plain HTML element — a `<div>` that you show, hide, and reposition using JavaScript as the mouse moves. The real challenge is detecting when the mouse enters, moves over, or leaves a specific feature on the map. Both Google Maps and Mapbox GL JS provide APIs for this, but they work differently: Google Maps attaches listeners to the Data layer, while Mapbox GL JS uses [`addInteraction()`](https://docs.mapbox.com/mapbox-gl-js/api/map/#map#addinteraction) to bind event handlers directly to a specific layer by ID.

First, add a tooltip element to your HTML, before the closing `</body>` tag:

```html
<div id="tooltip" style="
  position: fixed;
  background: rgba(0,0,0,0.75);
  color: #fff;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 13px;
  pointer-events: none;
  display: none;
"></div>
```

Then add the following helper functions inside your `<script>` tag, before the map initialization:

```js
const tooltip = document.getElementById('tooltip');

function showTooltip(x, y, name) {
  tooltip.textContent = name;
  tooltip.style.display = 'block';
  tooltip.style.left = (x + 15) + 'px';
  tooltip.style.top = (y - 28) + 'px';
}

function hideTooltip() {
  tooltip.style.display = 'none';
  map.getCanvas().style.cursor = '';
}
```

Both APIs support mouse event handlers on map features, but they attach differently. Google Maps listens on the Data layer globally; Mapbox GL JS targets a specific layer by ID and event type using `addInteraction()`.

### Google Maps JavaScript API

The Google Maps JavaScript API uses `data.addListener()` to attach event handlers to features in the Data layer:

```js
map.data.addListener('mousemove', (e) => {
  map.getDiv().style.cursor = 'pointer';
  showTooltip(e.domEvent.clientX, e.domEvent.clientY, e.feature.getProperty('name'));
});

map.data.addListener('mouseout', () => {
  hideTooltip();
});
```

![Google Maps JavaScript API with a hover tooltip showing a neighborhood name](https://docs.mapbox.com/help/ja/assets/ideal-img/tutorials--google-to-mapbox--google-step-5-add-interactivity.5f6dd06.480.png)

### Mapbox GL JS

Mapbox GL JS uses the [`addInteraction()`](https://docs.mapbox.com/mapbox-gl-js/api/map/#map#addinteraction) method to attach typed event handlers to specific layers. This is part of the Interactions API introduced in Mapbox GL JS v3.

Add the following code inside your `map.on('style.load', ...)` callback, after the layer definitions:

```js
map.addInteraction('neighborhoods-hover', {
  type: 'mousemove',
  target: { layerId: 'neighborhoods-fill' },
  handler(e) {
    showTooltip(e.originalEvent.clientX, e.originalEvent.clientY, e.feature.properties.name);
  }
});

map.addInteraction('neighborhoods-enter', {
  type: 'mouseenter',
  target: { layerId: 'neighborhoods-fill' },
  handler(e) {
    map.getCanvas().style.cursor = 'pointer';
    showTooltip(e.originalEvent.clientX, e.originalEvent.clientY, e.feature.properties.name);
  }
});

map.addInteraction('neighborhoods-leave', {
  type: 'mouseleave',
  target: { layerId: 'neighborhoods-fill' },
  handler() {
    hideTooltip();
  }
});
```

-   The first argument is a unique name for the interaction.
-   `type` specifies the event type — `mouseenter` fires once when the cursor enters a feature, `mousemove` fires continuously as it moves across the feature, and `mouseleave` fires when it exits.
-   `target.layerId` specifies which layer to listen on.
-   The `handler` function receives the event object, including `e.feature` for the feature under the cursor.

Save and refresh. Hover over a neighborhood to see its name in the tooltip.

The map is now fully interactive. In the final step, you'll customize the basemap colors to give the map a distinct visual style.

## Customize the basemap

One of the most powerful features of Mapbox is the ability to customize the map's visual style programmatically, without leaving your code editor.

Google Maps manages visual styles through the Cloud Console, referenced at runtime via a `mapId`. With the Mapbox Standard style, colors and themes are configured directly in your JavaScript code — no external console needed.

### Google Maps JavaScript API

The Google Maps JavaScript API uses **Cloud-based Map Styling**, where you configure visual styles in the Google Cloud Console and reference them with a `mapId`. Changing colors or other style properties requires updating the configuration in the console.

```js
// Styles are managed in the Google Cloud Console
const map = new google.maps.Map(document.getElementById('map'), {
  center: { lat: 40.73713, lng: -73.99365 },
  zoom: 11,
  mapId: 'YOUR_STYLED_MAP_ID'  // References styles configured in Google Cloud Console
});
```

![Google Maps with a custom color scheme applied via Cloud Map Styling](https://docs.mapbox.com/help/ja/assets/ideal-img/tutorials--google-to-mapbox--google-step-6-customize-basemap.8447a7b.480.png)

### Mapbox GL JS

With the [Mapbox Standard style](https://docs.mapbox.com/map-styles/standard/guides/), you can customize map colors directly in JavaScript at initialization time using the `config.basemap` option — no separate cloud console required.

Update your `Map` initialization to add a `config` object:

```js
const map = new mapboxgl.Map({
  accessToken: 'YOUR_MAPBOX_ACCESS_TOKEN',
  container: 'map',
  style: 'mapbox://styles/mapbox/standard',
  center: [-73.99365, 40.73713],
  zoom: 11.5,
  config: {
    basemap: {
      colorLand: '#f2ede4',
      colorWater: '#9dbfce',
      colorGreenspace: '#afc99a',
      colorMotorways: '#c8956c',
      colorRoads: '#e8dcc8'
    }
  }
});
```

You can also change these values at runtime using [`setConfigProperty()`](https://docs.mapbox.com/mapbox-gl-js/api/map/#map#setconfigproperty):

```js
// Change a color after the map has loaded
map.setConfigProperty('basemap', 'colorLand', '#e8f4e8');
```

> **Note: More Standard style configuration options**
> 
> The `config.basemap` object also supports `lightPreset` (dawn, day, dusk, night) and `theme` (faded, monochrome) besides individual color tokens. Try the [Mapbox Standard Style Playground](https://docs.mapbox.com/playground/standard-style/) to experiment with different settings via a graphical interface.
> 
> See the [Mapbox Standard API reference](https://docs.mapbox.com/map-styles/standard/api/) for the full list of configurable properties.

Save and refresh to see your customized basemap.

Your map now has a custom color palette applied at runtime — no style editor required. In the final step, you'll add a location search box.

## Add a search box

[Mapbox Search JS](https://docs.mapbox.com/mapbox-search-js/guides/) is a JavaScript library for adding location search to your web app. It includes a ready-to-use search box component that integrates directly with Mapbox GL JS, automatically flying the map to results and placing a marker at the selected location.

Google Maps provides location search through the Places API, requiring a custom input element and manual event handling. Mapbox Search JS provides a ready-to-use `MapboxSearchBox` component that plugs directly into the map as a control, handling fly-to and marker placement automatically.

### Google Maps JavaScript API

Google Maps provides location search through the Places API using `Autocomplete`:

```js
const input = document.getElementById('search-input');
const autocomplete = new google.maps.places.Autocomplete(input);
autocomplete.bindTo('bounds', map);

autocomplete.addListener('place_changed', () => {
  const place = autocomplete.getPlace();
  if (place.geometry?.location) {
    map.panTo(place.geometry.location);
    map.setZoom(15);
  }
});
```

### Mapbox GL JS

First, add the Mapbox Search JS library to your `<head>`, after the Mapbox GL JS imports:

```html
<script id="search-js" defer src="https://api.mapbox.com/search-js/v1.2.0/web.js"></script>
```

Then initialize the search box and add it to the map. Because the Search JS script is loaded with `defer`, wrap the initialization in a `window.addEventListener('load', ...)` callback to make sure the library is ready:

```js
window.addEventListener('load', () => {
  const searchBox = new MapboxSearchBox();
  searchBox.accessToken = 'YOUR_MAPBOX_ACCESS_TOKEN';
  searchBox.options = {
    types: 'address,poi',
    proximity: [-73.99365, 40.73713]
  };
  searchBox.marker = true;
  searchBox.mapboxgl = mapboxgl;
  map.addControl(searchBox);
});
```

-   `searchBox.options` sets the result types to return and biases results toward a location using `proximity`.
-   `searchBox.marker = true` places a marker automatically at the selected result.
-   `searchBox.mapboxgl = mapboxgl` connects the search box to the map library so the map flies to the selected result.
-   `map.addControl(searchBox)` adds the search box to the top-right corner of the map.

Save and refresh. Search for any address or point of interest in New York City — the map will fly to the result with a marker pinned at that location.

## Final product

You've built a complete web map using Mapbox GL JS and learned the equivalent of every Google Maps feature covered in this tutorial — from map initialization and markers to GeoJSON data, hover interactivity, programmatic basemap customization, and location search.

```html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Demo: Switch from Google Maps to Mapbox GL JS</title>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <script src="https://api.mapbox.com/mapbox-gl-js/v3.25.0/mapbox-gl.js"></script>
    <link
      href="https://api.mapbox.com/mapbox-gl-js/v3.25.0/mapbox-gl.css"
      rel="stylesheet"
    />
    <script
      id="search-js"
      defer
      src="https://api.mapbox.com/search-js/v1.2.0/web.js"
    ></script>
    <style>
      body {
        margin: 0;
        padding: 0;
      }

      #map {
        position: absolute;
        top: 0;
        bottom: 0;
        width: 100%;
      }

      #tooltip {
        position: fixed;
        background: rgb(0 0 0 / 75%);
        color: #fff;
        padding: 5px 10px;
        border-radius: 4px;
        font-family: sans-serif;
        font-size: 13px;
        pointer-events: none;
        display: none;
        z-index: 100;
      }
    </style>
  </head>
  <body>
    <div id="map"></div>
    <div id="tooltip"></div>
    <script>
      const tooltip = document.getElementById('tooltip');

      function showTooltip(x, y, name) {
        tooltip.textContent = name;
        tooltip.style.display = 'block';
        tooltip.style.left = x + 15 + 'px';
        tooltip.style.top = y - 28 + 'px';
      }

      function hideTooltip() {
        tooltip.style.display = 'none';
        map.getCanvas().style.cursor = '';
      }

      const neighborhoods = {
        type: 'FeatureCollection',
        features: [
          {
            type: 'Feature',
            properties: { name: 'Midtown' },
            geometry: {
              type: 'Polygon',
              coordinates: [
                [
                  [-73.9950637, 40.7722064],
                  [-73.9597323, 40.7592046],
                  [-73.9721082, 40.7434781],
                  [-73.9725075, 40.7348572],
                  [-74.0094358, 40.7495272],
                  [-74.0094358, 40.7533076],
                  [-73.9992555, 40.7651011],
                  [-73.9962613, 40.7684271],
                  [-73.9950637, 40.7722064]
                ]
              ]
            }
          },
          {
            type: 'Feature',
            properties: { name: 'Financial District' },
            geometry: {
              type: 'Polygon',
              coordinates: [
                [
                  [-74.0157699, 40.7163373],
                  [-74.0050355, 40.71292],
                  [-73.9983801, 40.7072241],
                  [-74.0097586, 40.7008767],
                  [-74.0153406, 40.7003885],
                  [-74.0183462, 40.7026671],
                  [-74.0202784, 40.7051084],
                  [-74.0157699, 40.7163373]
                ]
              ]
            }
          }
        ]
      };

      const map = new mapboxgl.Map({
        accessToken: 'YOUR_MAPBOX_ACCESS_TOKEN',
        container: 'map',
        style: 'mapbox://styles/mapbox/standard',
        center: [-73.99365, 40.73713],
        zoom: 11.5,
        config: {
          basemap: {
            colorLand: '#f2ede4',
            colorWater: '#9dbfce',
            colorGreenspace: '#afc99a',
            colorMotorways: '#c8956c',
            colorRoads: '#e8dcc8'
          }
        }
      });

      const popup = new mapboxgl.Popup({ offset: 25 }).setHTML(
        "<h3>Empire State Building</h3><p>Constructed in just 410 days — and for 40 years it held the record as the world's tallest building.</p>"
      );

      const marker = new mapboxgl.Marker()
        .setLngLat([-73.9857, 40.7484])
        .setPopup(popup)
        .addTo(map);
      marker.togglePopup();

      map.on('style.load', () => {
        map.addSource('neighborhoods', {
          type: 'geojson',
          data: neighborhoods
        });

        map.addLayer({
          id: 'neighborhoods-fill',
          type: 'fill',
          source: 'neighborhoods',
          paint: {
            'fill-color': '#3b82f6',
            'fill-opacity': 0.35
          }
        });

        map.addLayer({
          id: 'neighborhoods-outline',
          type: 'line',
          source: 'neighborhoods',
          paint: {
            'line-color': '#1d4ed8',
            'line-width': 2
          }
        });

        map.addInteraction('neighborhoods-hover', {
          type: 'mousemove',
          target: { layerId: 'neighborhoods-fill' },
          handler(e) {
            showTooltip(
              e.originalEvent.clientX,
              e.originalEvent.clientY,
              e.feature.properties.name
            );
          }
        });

        map.addInteraction('neighborhoods-enter', {
          type: 'mouseenter',
          target: { layerId: 'neighborhoods-fill' },
          handler(e) {
            map.getCanvas().style.cursor = 'pointer';
            showTooltip(
              e.originalEvent.clientX,
              e.originalEvent.clientY,
              e.feature.properties.name
            );
          }
        });

        map.addInteraction('neighborhoods-leave', {
          type: 'mouseleave',
          target: { layerId: 'neighborhoods-fill' },
          handler() {
            hideTooltip();
          }
        });
      });

      window.addEventListener('load', () => {
        const searchBox = new MapboxSearchBox();
        searchBox.accessToken = 'YOUR_MAPBOX_ACCESS_TOKEN';
        searchBox.options = {
          types: 'address,poi',
          proximity: [-73.99365, 40.73713]
        };
        searchBox.marker = true;
        searchBox.mapboxgl = mapboxgl;
        map.addControl(searchBox);
      });
    </script>
  </body>
</html>
```

## Next steps

**Congratulations!** You have made the switch from Google Maps to Mapbox GL JS.

### What we covered

-   Initializing a [Mapbox GL JS](https://docs.mapbox.com/mapbox-gl-js/) map
-   Adding a [Marker](https://docs.mapbox.com/mapbox-gl-js/api/markers/#marker) and [Popup](https://docs.mapbox.com/mapbox-gl-js/api/markers/#popup)
-   Loading GeoJSON data using sources and layers
-   Adding hover interactivity with [`addInteraction()`](https://docs.mapbox.com/mapbox-gl-js/api/map/#map#addinteraction)
-   Customizing the [Mapbox Standard](https://docs.mapbox.com/map-styles/standard/guides/) basemap with `config.basemap`
-   Adding a location search box with [Mapbox Search JS](https://docs.mapbox.com/mapbox-search-js/guides/)

Continue building with these tutorials and guides:

> **Related content (tutorial): [Create a custom style](https://docs.mapbox.com/help/ja/tutorials/create-a-custom-style/)**
> 
> Design a fully custom map style in Mapbox Studio and use it in your web application.

> **Related content (tutorial): [Configure the basemap in Mapbox GL JS](https://docs.mapbox.com/help/ja/tutorials/configure-basemap-mapbox-gl-js/)**
> 
> Go deeper with lighting presets, color themes, and individual component colors for the Mapbox Standard style.

> **Related content (guide): [Mapbox Search JS](https://docs.mapbox.com/mapbox-search-js/guides/)**
> 
> Learn more about adding search, autocomplete, and address autofill to your web application.

> **Related content (example): [Mapbox GL JS examples](https://docs.mapbox.com/mapbox-gl-js/example/)**
> 
> Browse hundreds of Mapbox GL JS examples with code snippets you can copy and paste.