0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

@react-google-maps/apiのマーカーのアイコンを表示する方法

Last updated at Posted at 2024-02-10

目次

1. 問題解決の経緯
2. 開発環境
3. 解決方法
4. 結果
5. おわりに

1. 問題解決の経緯

ググって出てきた方法が悉く通用しなかったので、備忘録として残します。

2. 開発環境

Package Version
next 14.0.4
react ^18
@react-google-maps/api 2.19.2

3. 解決方法

アイコンのパスをimportして任意の変数に格納します。
そして、MarkerFコンポーネントのiconプロパティに変数.srcを代入します。

page.tsx
import { GoogleMap, MarkerF } from "@react-google-maps/api";
import iconPath from "../../../public/images/icon.png";

const Page = () => {
...
  return (
    ...
    <GoogleMap>
      <MarkerF visible={true} position={...} icon={iconPath.src} />
    </GoogleMap>
    ...
  );
};

4. 結果

以下のように表示されるようになります。(真ん中のやつ)

スクリーンショット 2024-02-10 22.55.24.png

5. おわりに

たまたまiconプロパティのサジェストから見つけたのでラッキーでした💫

以上です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?