ヒートマップ レイヤ
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
- 概要
- 可視化ライブラリのロード
- 重み付きデータポイントの追加
- ヒートマップ レイヤのカスタマイズ
ヒートマップ レイヤは、クライアント側でのヒートマップのレンダリングを可能にします。
概要
ヒートマップは、地理的なポイントのデータの強度を表すために使用する可視化ツールです。ヒートマップ レイヤが有効である場合、色付きのオーバーレイが地図の上に表示されます。デフォルトでは、高い強度の領域が赤色、低い強度の領域が緑色で表されます。
可視化ライブラリのロード
ヒートマップ レイヤは google.maps.visualization
ライブラリの一部であり、デフォルトでは読み込まれません。可視化クラスは、メインの Maps JavaScript API コードとは別の自己完結型のライブラリです。このライブラリの機能を利用するには、最初に Maps JavaScript API ブートストラップ URL の libraries
パラメータを使用してライブラリを読み込む必要があります。
<script async
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&loading=async&libraries=visualization&callback=initMap">
</script>
ヒートマップ レイヤの追加
ヒートマップ レイヤを追加するには、まず、新しい HeatmapLayer
オブジェクトを作成してから、地理データを配列または MVCArray[]
オブジェクトの形式で指定します。データは、LatLng
オブジェクトまたは WeightedLocation
オブジェクトです。HeatmapLayer
オブジェクトをインスタンス化したら、setMap()
メソッドを呼び出して地図に追加します。
次の例では、14 個のデータポイントをサンフランシスコの地図に追加しています。
/* Data points defined as an array of LatLng objects */
var heatmapData = [
new google.maps.LatLng(37.782, -122.447),
new google.maps.LatLng(37.782, -122.445),
new google.maps.LatLng(37.782, -122.443),
new google.maps.LatLng(37.782, -122.441),
new google.maps.LatLng(37.782, -122.439),
new google.maps.LatLng(37.782, -122.437),
new google.maps.LatLng(37.782, -122.435),
new google.maps.LatLng(37.785, -122.447),
new google.maps.LatLng(37.785, -122.445),
new google.maps.LatLng(37.785, -122.443),
new google.maps.LatLng(37.785, -122.441),
new google.maps.LatLng(37.785, -122.439),
new google.maps.LatLng(37.785, -122.437),
new google.maps.LatLng(37.785, -122.435)
];
var sanFrancisco = new google.maps.LatLng(37.774546, -122.433523);
map = new google.maps.Map(document.getElementById('map'), {
center: sanFrancisco,
zoom: 13,
mapTypeId: 'satellite'
});
var heatmap = new google.maps.visualization.HeatmapLayer({
data: heatmapData
});
heatmap.setMap(map);
重み付きデータポイントの追加
ヒートマップでは、LatLng
オブジェクト、WeightedLocation
オブジェクト、またはこの 2 つのオブジェクトの組み合わせをレンダリングできます。いずれのオブジェクトも地図上の単一のデータポイントを表しますが、WeightedLocation
オブジェクトを使用すると、さらにそのデータポイントの重みを指定できます。データポイントに重みを適用すると、WeightedLocation
は単純な LatLng
オブジェクトより高い強度でレンダリングされます。重みはリニアスケールであり、各 LatLng
オブジェクトの重みは暗黙的に 1 となります。{location: new google.maps.LatLng(37.782, -122.441), weight: 3}
の WeightedLocation
を 1 つ追加すると、google.maps.LatLng(37.782, -122.441)
を 3 回追加した場合と同じ効果が生じます。単一の配列内で weightedLocation
オブジェクトと LatLng
オブジェクトを組み合わせることができます。
LatLng
の代わりに WeightedLocation
オブジェクトを使用すると、次のような場合に便利です。
- 1 つの場所で大量のデータを追加する。重みが 1,000 の
WeightedLocation
オブジェクトを 1 つレンダリングする方が、1,000 個の LatLng
オブジェクトをレンダリングするよりも高速です。
- 任意の値に基づいてデータを強調する。たとえば、地震データを地図に指定するときに
LatLng
オブジェクトを使用できますが、WeightedLocation
を使用すれば、各地震のマグニチュードをより細かく数値化できます。
/* Data points defined as a mixture of WeightedLocation and LatLng objects */
var heatMapData = [
{location: new google.maps.LatLng(37.782, -122.447), weight: 0.5},
new google.maps.LatLng(37.782, -122.445),
{location: new google.maps.LatLng(37.782, -122.443), weight: 2},
{location: new google.maps.LatLng(37.782, -122.441), weight: 3},
{location: new google.maps.LatLng(37.782, -122.439), weight: 2},
new google.maps.LatLng(37.782, -122.437),
{location: new google.maps.LatLng(37.782, -122.435), weight: 0.5},
{location: new google.maps.LatLng(37.785, -122.447), weight: 3},
{location: new google.maps.LatLng(37.785, -122.445), weight: 2},
new google.maps.LatLng(37.785, -122.443),
{location: new google.maps.LatLng(37.785, -122.441), weight: 0.5},
new google.maps.LatLng(37.785, -122.439),
{location: new google.maps.LatLng(37.785, -122.437), weight: 2},
{location: new google.maps.LatLng(37.785, -122.435), weight: 3}
];
var sanFrancisco = new google.maps.LatLng(37.774546, -122.433523);
map = new google.maps.Map(document.getElementById('map'), {
center: sanFrancisco,
zoom: 13,
mapTypeId: 'satellite'
});
var heatmap = new google.maps.visualization.HeatmapLayer({
data: heatMapData
});
heatmap.setMap(map);
ヒートマップ レイヤのカスタマイズ
以下のヒートマップ オプションを使用して、ヒートマップのレンダリング方法をカスタマイズできます。詳しくは、HeatmapLayerOptions
のドキュメントをご覧ください。
dissipating
: ズーム時にヒートマップを非表示にするかどうかを指定します。Dissipating が false の場合、影響の半径がズームレベルに伴って増加し、指定されているすべての地理的な場所で色強度が保持されます。デフォルトは true です。
gradient
: ヒートマップのカラー グラデーションです。CSS 色文字列の配列として指定されます。名前付きの拡張色と HSL(A) 値を除くすべての CSS3 色(RGBA を含む)がサポートされています。
maxIntensity
: ヒートマップの最大強度です。デフォルトでは、ヒートマップ色は地図上の全ピクセルでポイントの最大濃度に応じて動的に変化します。このプロパティを使用すると、固定の最大値を指定できます。データセットに著しく高い強度の異常値がいくつか含まれている場合に、最大強度を設定すると便利な場合があります。
radius
: 各データポイントの影響の半径です(ピクセル単位)。
opacity
: 0 から 1 の間の数で表されるヒートマップの不透明度です。
下のサンプルは、利用可能ないくつかのカスタマイズ オプションを示しています。
サンプルを表示
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-06-16 UTC。
[null,null,["最終更新日 2025-06-16 UTC。"],[[["\u003cp\u003eThe Heatmap Layer visualizes data intensity at geographical points using color gradients, typically with red for high intensity and green for low.\u003c/p\u003e\n"],["\u003cp\u003eTo use the Heatmap Layer, you must load the \u003ccode\u003egoogle.maps.visualization\u003c/code\u003e library using the \u003ccode\u003elibraries\u003c/code\u003e parameter in the Maps JavaScript API bootstrap URL.\u003c/p\u003e\n"],["\u003cp\u003eHeatmaps can be customized using options like \u003ccode\u003edissipating\u003c/code\u003e, \u003ccode\u003egradient\u003c/code\u003e, \u003ccode\u003emaxIntensity\u003c/code\u003e, \u003ccode\u003eradius\u003c/code\u003e, and \u003ccode\u003eopacity\u003c/code\u003e to control their appearance and behavior.\u003c/p\u003e\n"],["\u003cp\u003eData points for the heatmap can be provided as \u003ccode\u003eLatLng\u003c/code\u003e objects or \u003ccode\u003eWeightedLocation\u003c/code\u003e objects, with the latter allowing for specifying the intensity of each point using a weight value.\u003c/p\u003e\n"]]],[],null,["Select platform: [Android](/maps/documentation/android-sdk/utility/heatmap \"View this page for the Android platform docs.\") [iOS](/maps/documentation/ios-sdk/utility/heatmap \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/heatmaplayer \"View this page for the JavaScript platform docs.\")\n\n1. [Overview](#overview)\n2. [Load the visualization library](#load_the_visualization_library)\n3. [Add Weighted Data Points](#add_weighted_data_points)\n4. [Customize a Heatmap Layer](#customize_a_heatmap_layer)\n\n| **[Deprecated:](/maps/deprecations)** The Heatmap Layer\n| functionality in the Maps JavaScript API will no longer be supported. This API was deprecated in\n| May 2025 and be made unavailable in a later version of the Maps JavaScript API, releasing in May\n| 2026. As a replacement for the Heatmap Layer, consider using third-party library integrations\n| like deck.gl, which offers a HeatmapLayer implementation. You can find more information in the\n| [deck.gl documentation](https://deck.gl/docs/api-reference/aggregation-layers/heatmap-layer).\n\nThe Heatmap Layer provides client side rendering of heatmaps.\n\nOverview\n\nA heatmap is a visualization used to depict the intensity of data at\ngeographical points. When the Heatmap Layer is enabled, a colored overlay will\nappear on top of the map. By default, areas of higher intensity will be colored\nred, and areas of lower intensity will appear green.\n\nLoad the visualization library\n\nThe Heatmap Layer is part of the `google.maps.visualization` library, and is not\nloaded by default. The Visualization classes are a self-contained library,\nseparate from the main Maps JavaScript API code. To use the functionality\ncontained within this library, you must first load it using the `libraries`\nparameter in the Maps JavaScript API bootstrap URL: \n\n```html\n\u003cscript async\n src=\"https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&loading=async&libraries=visualization&callback=initMap\"\u003e\n\u003c/script\u003e\n```\n\nAdd a Heatmap Layer\n\nTo add a Heatmap Layer, you must first create a new `HeatmapLayer`\nobject, and provide it with some geographic data in the form of an array or an\n`MVCArray[]` object. The data may be either a\n[`LatLng`](/maps/documentation/javascript/reference#LatLng)\nobject or a\n[`WeightedLocation`](/maps/documentation/javascript/reference#WeightedLocation)\nobject. After instantiating the `HeatmapLayer` object, add it to the\nmap by calling the `setMap()` method.\n\nThe following example adds 14 data points to a map of San Francisco. \n\n```javascript\n/* Data points defined as an array of LatLng objects */\nvar heatmapData = [\n new google.maps.LatLng(37.782, -122.447),\n new google.maps.LatLng(37.782, -122.445),\n new google.maps.LatLng(37.782, -122.443),\n new google.maps.LatLng(37.782, -122.441),\n new google.maps.LatLng(37.782, -122.439),\n new google.maps.LatLng(37.782, -122.437),\n new google.maps.LatLng(37.782, -122.435),\n new google.maps.LatLng(37.785, -122.447),\n new google.maps.LatLng(37.785, -122.445),\n new google.maps.LatLng(37.785, -122.443),\n new google.maps.LatLng(37.785, -122.441),\n new google.maps.LatLng(37.785, -122.439),\n new google.maps.LatLng(37.785, -122.437),\n new google.maps.LatLng(37.785, -122.435)\n];\n\nvar sanFrancisco = new google.maps.LatLng(37.774546, -122.433523);\n\nmap = new google.maps.Map(document.getElementById('map'), {\n center: sanFrancisco,\n zoom: 13,\n mapTypeId: 'satellite'\n});\n\nvar heatmap = new google.maps.visualization.HeatmapLayer({\n data: heatmapData\n});\nheatmap.setMap(map);\n```\n\nAdd Weighted Data Points\n\nA heatmap can render either\n[`LatLng`](/maps/documentation/javascript/reference#LatLng) or\n[`WeightedLocation`](/maps/documentation/javascript/reference#WeightedLocation)\nobjects, or a combination of the two. Both objects represent a single data\npoint on a map, but a `WeightedLocation` object allows you to additionally\nspecify a weight for that data point. Applying a weight to a data point will\ncause the `WeightedLocation` to be rendered with a greater intensity than a\nsimple `LatLng` object. The weight is a linear scale, in which each `LatLng`\nobject has an implicit weight of 1 --- adding a single `WeightedLocation`\nof `{location: new google.maps.LatLng(37.782, -122.441), weight: 3}` will have\nthe same effect as adding `google.maps.LatLng(37.782, -122.441)` three times.\nYou can mix `weightedLocation` and `LatLng` objects in a single array.\n\nUsing a `WeightedLocation` object in place of a `LatLng` can be useful when:\n\n- Adding large amounts of data at a single location. Rendering a single `WeightedLocation` object with a weight of 1000 will be faster than rendering 1000 `LatLng` objects.\n- Applying an emphasis to your data based upon arbitrary values. For example, you can use `LatLng` objects when plotting earthquake data, but you may want to use a `WeightedLocation` to measure the magnitude of each earthquake on the richter scale.\n\n```javascript\n/* Data points defined as a mixture of WeightedLocation and LatLng objects */\nvar heatMapData = [\n {location: new google.maps.LatLng(37.782, -122.447), weight: 0.5},\n new google.maps.LatLng(37.782, -122.445),\n {location: new google.maps.LatLng(37.782, -122.443), weight: 2},\n {location: new google.maps.LatLng(37.782, -122.441), weight: 3},\n {location: new google.maps.LatLng(37.782, -122.439), weight: 2},\n new google.maps.LatLng(37.782, -122.437),\n {location: new google.maps.LatLng(37.782, -122.435), weight: 0.5},\n\n {location: new google.maps.LatLng(37.785, -122.447), weight: 3},\n {location: new google.maps.LatLng(37.785, -122.445), weight: 2},\n new google.maps.LatLng(37.785, -122.443),\n {location: new google.maps.LatLng(37.785, -122.441), weight: 0.5},\n new google.maps.LatLng(37.785, -122.439),\n {location: new google.maps.LatLng(37.785, -122.437), weight: 2},\n {location: new google.maps.LatLng(37.785, -122.435), weight: 3}\n];\n\nvar sanFrancisco = new google.maps.LatLng(37.774546, -122.433523);\n\nmap = new google.maps.Map(document.getElementById('map'), {\n center: sanFrancisco,\n zoom: 13,\n mapTypeId: 'satellite'\n});\n\nvar heatmap = new google.maps.visualization.HeatmapLayer({\n data: heatMapData\n});\nheatmap.setMap(map);\n```\n\nCustomize a Heatmap Layer\n\nYou can customize how your heatmap will be rendered with the following heatmap\noptions. See the\n[`HeatmapLayerOptions`](/maps/documentation/javascript/reference#HeatmapLayerOptions) documentation for more information.\n\n- `dissipating`: Specifies whether heatmaps dissipate on zoom. When dissipating is false the radius of influence increases with zoom level to ensure that the color intensity is preserved at any given geographic location. Defaults to true.\n- `gradient`: The color gradient of the heatmap, specified as an array of CSS color strings. All [CSS3 colors](http://www.w3.org/TR/css3-color/#html4) --- including RGBA --- are supported except for [extended named\n colors](http://www.w3.org/TR/css3-color/#svg-color) and HSL(A) values.\n- `maxIntensity`: The maximum intensity of the heatmap. By default, heatmap colors are dynamically scaled according to the greatest concentration of points at any particular pixel on the map. This property allows you to specify a fixed maximum. Setting the maximum intensity can be helpful when your dataset contains a few outliers with an unusually high intensity.\n- `radius`: The radius of influence for each data point, in pixels.\n- `opacity`: The opacity of the heatmap, expressed as a number between 0 and 1.\n\nThe below example shows some of the customization options available.\n\n[View example](/maps/documentation/javascript/examples/layer-heatmap)"]]