Google Maps Platform을 톡해 μ£Όμ†Œ λ˜λŠ” μœ„ β€’ 경도 정보λ₯Ό μ‘°νšŒν•  수 μžˆλ‹€. Places λ˜λŠ” Geocoding API λͺ¨λ‘μ—μ„œ ν•œκ΅­μ–΄λ₯Ό ν¬ν•¨ν•œ λ‹€μ–‘ν•œ 언어에 λŒ€ν•΄ 검색을 μ§€μ›ν•œλ‹€. 비둝 κ΅­λ‚΄ λŒ€μƒμœΌλ‘œ μ‚¬μš©ν•  수 μžˆλŠ” 우편번호 μ„œλΉ„μŠ€λ₯Ό μ‚¬μš©ν•˜λŠ” 것보닀 μžμ„Έν•œ 정보λ₯Ό κ°€μ Έμ˜€κΈ°λŠ” νž˜λ“€μ§€λ§Œ κ΅­λ‚΄ μ£Όμ†Œ 뿐만 μ•„λ‹ˆλΌ ν•΄μ™Έ μ£Όμ†Œλ‚˜ μœ„μΉ˜μ— λŒ€ν•œ 검색을 μ»€λ²„ν•˜κΈ° μœ„ν•΄μ„œλŠ” 거의 λŒ€μ•ˆμ΄ μ—†λ‹€κ³  μƒκ°λœλ‹€. λ˜ν•œ, HTTP μš”μ²­μ„ 직접 μ‚¬μš©ν•΄μ„œ κ΅¬ν˜„ν•˜μ§€ μ•Šμ•„λ„ μ‰½κ²Œ μ μš©ν•  수 μžˆλŠ” λΌμ΄λΈŒλŸ¬λ¦¬κ°€ μžˆλ‹€.

[FE] Vue 3 Google maps

import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import VueGoogleMaps from '@fawmi/vue-google-maps'

const app = createApp(App)
app.use(VueGoogleMaps, {
    load: {
        key: import.meta.env.VITE_GOOGLE_MAP_API_KEY,
        libraries: "places",
        language: 'ja'
    }
})
app.mount('#app')
<GMapAutocomplete
    placeholder="Please input address"
    @place_changed="(result) => console.log(result)">
</GMapAutocomplete>

[BE] Java Client for Google Maps Services

build.gradle
dependencies { implementation 'com.google.maps:google-maps-services:2.2.0' }
@SpringBootTest
class GoogleMapTests {

    static final String apiKey = "";
    static final Gson gson = new GsonBuilder().setPrettyPrinting().create();

    @Test
    void Test_Places() {
        Assertions.assertDoesNotThrow(() -> {
            GeoApiContext context = new GeoApiContext.Builder()
                    .apiKey(apiKey)
                    .queryRateLimit(10)
                    .build();
            PlaceAutocompleteRequest.SessionToken session = new PlaceAutocompleteRequest.SessionToken();

            String input = "강남역";
            AutocompletePrediction[] predictions = PlacesApi.placeAutocomplete(context, input, session).await();

            System.out.println(gson.toJson(predictions));
            context.shutdown();
        });
    }

}

Place Autocomplete μ΅œμ ν™”

Places API 와 Geocoding API λͺ¨λ‘ μ‚¬μš©ν•œ 만큼 μ§€λΆˆν•˜λŠ” 가격 λͺ¨λΈμ„ κ°€μ§€λ―€λ‘œ Place Autocomplete μ΅œμ ν™” 와 μ£Όμ†Œ μ§€μ˜€μ½”λ”© ꢌμž₯사항 같은 정보가 도움이 될 수 μžˆλ‹€. μ£Όμ†Œμ— λŒ€ν•œ μžμ„Έν•œ 정보가 ν•„μš”ν•œ 것이 μ•„λ‹Œ μ£Όμ†Œ 및 μœ„μΉ˜ μ •λ³΄λ§Œ ν•„μš”λ‘œ ν•˜λŠ” κ²½μš°μ—λŠ” μ•„λž˜μ˜ ν•­λͺ©μ„ 체크해보도둝 ν•˜μž.

  • μ£Όμ†Œμ™€ μœ„μΉ˜ μ •λ³΄λ§Œμ„ ν•„μš”λ‘œ ν•œλ‹€λ©΄ Place Autocomplete λ³΄λ‹€λŠ” Geocoding APIκ°€ νš¨μœ¨μ μ΄λ‹€.
  • μ‚¬μš©μžκ°€ μ›ν•˜λŠ” μ£Όμ†Œλ₯Ό λͺ…ν™•ν•˜κ²Œ μ•Œκ³  μžˆλ‹€λ©΄ Geocoding APIλ₯Ό μ‚¬μš©ν•˜λŠ”κ²Œ μ’‹λ‹€.
@SpringBootTest
class GoogleMapTests {

    static final String apiKey = "";
    static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
    static GeoApiContext context;

    @BeforeAll
    static void contextLoads() {
        context = new GeoApiContext.Builder()
                .apiKey(apiKey)
                .queryRateLimit(10)
                .build();
    }
    
    @Test
    void Test_Geocoding() {
        Assertions.assertDoesNotThrow(() -> {
            String address = "강남역";
            GeocodingResult[] results =  GeocodingApi.geocode(context, address)
                    .language("ko")
                    .locationType(LocationType.ROOFTOP)
                    .resultType(AddressType.STREET_ADDRESS)
                    .await();

            System.out.println(gson.toJson(results));
            context.shutdown();
        });
    }

}

Samples