-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from Duri-Salon/refactor/geocoding
[refactor] google maps geocoding
- Loading branch information
Showing
6 changed files
with
26 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
</head> | ||
<body> | ||
<div id="app"></div> | ||
|
||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,29 @@ | ||
import { Coordinates } from '@salon/types'; | ||
import axios from 'axios'; | ||
|
||
const NAVER_MAP_CLIENT_ID = import.meta.env.VITE_NAVER_MAP_CLIENT_ID; | ||
const NAVER_MAP_CLIENT_KEY = import.meta.env.VITE_NAVER_MAP_CLIENT_KEY; | ||
const GOOGLE_MAP_API_KEY = import.meta.env.VITE_GOOGLE_MAP_API_KEY; | ||
|
||
/** 도로명주소 -> 위도/경도 */ | ||
export const getGeocoding = async (query: string): Promise<Coordinates> => { | ||
const response = await axios.get('/naver-api/map-geocode/v2/geocode', { | ||
params: { | ||
query: query, | ||
}, | ||
headers: { | ||
'x-ncp-apigw-api-key-id': NAVER_MAP_CLIENT_ID, | ||
'x-ncp-apigw-api-key': NAVER_MAP_CLIENT_KEY, | ||
Accept: 'application/json', | ||
}, | ||
}); | ||
const { y, x } = response.data.addresses[0]; | ||
const lat = parseFloat(y); | ||
const lon = parseFloat(x); | ||
return { lat, lon }; | ||
try { | ||
const response = await axios.get( | ||
`https://maps.googleapis.com/maps/api/geocode/json`, | ||
{ | ||
params: { | ||
address: query, | ||
key: GOOGLE_MAP_API_KEY, | ||
}, | ||
}, | ||
); | ||
|
||
if (response.data.status !== 'OK') { | ||
throw new Error('지오코딩 실패'); | ||
} | ||
|
||
const { lat, lng } = response.data.results[0].geometry.location; | ||
return { lat, lon: lng }; | ||
} catch (error) { | ||
console.error('지오코딩 에러:', error); | ||
throw new Error('주소를 검색할 수 없습니다.'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,3 @@ | ||
{ | ||
"rewrites": [ | ||
{ "source": "/(.*)", "destination": "/" }, | ||
{ | ||
"source": "/naver-api/:path*", | ||
"destination": "https://naveropenapi.apigw.ntruss.com/:path*" | ||
} | ||
] | ||
"rewrites": [{ "source": "/(.*)", "destination": "/" }] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters