Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GoogleMapのAPIを一旦叩けるようにした #8

Merged
merged 9 commits into from
Jan 12, 2025
Merged

Conversation

takatea
Copy link
Contributor

@takatea takatea commented Dec 9, 2024

さまりー

一旦Map APIは叩けるようにしておいた
ただ、Route APIどうやって使うかは別途確認しなきゃいけない...!
→ シュッと使えないかも

やったこと

  • 環境変数周りの整備
  • @vis.gl/react-google-mapsを入れた

できたやつ

Mapはこんな感じ

image

Directions API

こんな感じ
image

ref: https://visgl.github.io/react-google-maps/examples/directions

Route API使いたい。が参考になるコードがシュッと見つからなかったのでちゃんとコード書かないといけないかも

以下でAPIキーしぼってます

image

ちょっと調べた

既存の「Directions API」、「Distance Matrix API」のアップグレード版

https://www.zenrin-datacom.net/solution/blog/gmpupdate-002

らしいので、Route APIを頑張って作るのが良きね。
-> もうちょい調べた

https://stackoverflow.com/questions/78081216/using-new-google-routes-api-how-can-i-render-show-route-result-to-a-map

にあるように、Routes APIはフロントでrenderするための機能は提供していないっぽい。
なので、Directions APIとDistance Matrix APIを使うのが無難かも。

もしRoutes API使うならバックエンドからAPI叩いて(フロントでもまぁいいけど)、データをバックエンドから取得して、フロントで表示とかになるんとちゃうかな。

@takatea takatea force-pushed the can-use-google-api branch from 54c8b2a to 9f63307 Compare December 9, 2024 13:28
@takatea takatea requested a review from RYoJiy December 9, 2024 13:28
@takatea takatea self-assigned this Dec 9, 2024
export default function Index() {
const position = { lat: 35.689501375244, lng: 139.69173371705 };

return (
Copy link
Contributor Author

@takatea takatea Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

component: Index,
});

const API_KEY = import.meta.env.FRONTEND_GOOGLE_API_KEY;
Copy link
Contributor Author

@takatea takatea Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これはviteの環境変数のimport方法なんだけど、環境変数まわりの管理方法はもうちょい考えたいかも

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

確かにな。今のままでは流石にダサいから、要検討でw

Copy link
Contributor

@RYoJiy RYoJiy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@takatea
サンプルありがとう〜!
localでもGoogleのAPI叩いてMapが見れるところまで確認できた!

レビューめっちゃ遅くなってすまそ

directionsService
.route({
origin: "東京都新宿区西新宿2丁目8-1", // 都庁
waypoints: [{ location: "東京都港区赤坂9-7-1", stopover: true }], // ミッドタウン
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最大25waypointsまでらしいわ。余裕で行けそう。
仮に25を超えるとしても、別々で計算して後でがっちゃんこするみたいなこともできるらしいし、とりま心配なさそうやな。
https://arc.net/l/quote/ucbmiyla

component: Index,
});

const API_KEY = import.meta.env.FRONTEND_GOOGLE_API_KEY;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

確かにな。今のままでは流石にダサいから、要検討でw

@takatea takatea merged commit 46a11b5 into main Jan 12, 2025
1 check passed
@takatea takatea deleted the can-use-google-api branch January 12, 2025 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants