κ΅¬κΈ μ£Όμ κ²μμΌλ‘ μ κ²½λ μ‘°ν
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
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();
});
}
}