LWCで取引先などの住所を地図上にマーカーをプロットする方法について記録しておきます。 公式マニュアルの以下のページでLWCのMapというコンポーネントが紹介されています。
https://developer.salesforce.com/docs/component-library/bundle/lightning-map/documentation
取引先から住所を取得して地図にプロットするごくシンプルなコードを掲載しておきます。 lightning-mapコンポーネントのmap-markersプロパティにプロットしたい住所を突っ込みます。
<template>
<lightning-map
map-markers={mapMarkers}
zoom-level="10"
list-view="hidden"
show-footer
markers-title="お客様">
</lightning-map>
</template>import { LightningElement } from 'lwc';
export default class AccountAddressMapping extends LightningElement {
mapMarkers = [{title: '東京都庁',
location: {
City: '新宿区西新宿',
PostalCode: '163-8001',
State: '東京都',
Street: '2丁目8−1',},
},
{title: '埼玉県庁',
location: {
City: 'さいたま市浦和区高砂',
PostalCode: '330-9301',
State: '埼玉県',
Street: '3丁目15−1',}
},
{title: '千葉県庁',
location: {
City: '千葉市中央区市場町',
PostalCode: '260-0855',
State: '千葉県',
Street: '1−1',}
}];
}こんな感じで表示されます。

ところがLWCのマニュアル内に気になる記述が。 冒頭でご紹介したLWCマニュアルのMapコンポーネントの下の方に次のように書かれています。
The
lightning-mapcomponent relies on data from Google for geocoding and mapping imagery. Inaccuracies or geocoding errors in the data can’t be fixed by Salesforce.You can specify a maximum of 10 geocoded address lookups per map. Lookups for both the
https://developer.salesforce.com/docs/component-library/bundle/lightning-map/documentationmap-markersandcenterattributes count toward the limit of 10 geocoded addresses. To display more markers, provide location values using a pair of latitude and longitude coordinates, which don’t require geocoding. Address locations that exceed the geocoding limit are ignored.
「東京都新宿区西新宿2丁目8−1」のような通常の住所(?)を指定した場合、10か所までしか地図上にプロットできないようなのです。代わりに経度・緯度を指定すればその制限がなくなります。 住所を経度・緯度に変換する方法は次の記事でご紹介します。