You want address autocomplete in a Vue 3 checkout form. You search npm for a Vue package, and for Geoapify there isn't one: there's a React wrapper and a plain JavaScript library.

Good news: you don't need a wrapper. In this tutorial we build a small Vue component around the plain library, fill a v-model form from the selected address, and make sure the component cleans up after itself. Then we ask an AI coding assistant to build the same thing and see what the prompt changes.

TL;DR

  • @geoapify/geocoder-autocomplete has no framework dependency. A Vue component for it is about 25 lines: create it in onMounted, forward select, call destroy() in onBeforeUnmount.
  • Skip destroy() and every unmount leaves a click listener on document. We measured it: after 5 unmount/mount cycles, 6 listeners instead of 1.
  • The selected address comes back as GeoJSON with the same properties in every country (street, housenumber, postcode, city, state, country), so mapping it to form fields is six lines.
  • A vague prompt to an AI assistant got a working form built on the library's 2022 version (1.5.1), with no destroy() and an extra API request per selection. A precise prompt got the same component as our hand-written demo.

👉 Live demo: type an address and pick a suggestion.

Table of Contents

  1. What we're building
  2. Why a wrapper needs destroy()
  3. Step 1: Load Vue and the library
  4. Step 2: The AddressAutocomplete component
  5. Step 3: Fill a v-model form from the selected address
  6. The same component in a Vite project
  7. Let an AI assistant write it
  8. Summary
  9. FAQ

What we're building

One search field and a normal address form. The user types "350 5th Ave, New York", picks the Empire State Building, and six inputs fill in: street, house number, postcode, city, state and country. Every input stays editable, because autocomplete suggests and the user confirms.

Vue 3 address autocomplete: on the left the suggestion list for "350 5th Ave, New York", on the right the form filled with 5th Avenue, 350, 10118, New York, New York, United States and the reactive form state as JSON

The structure is the usual Vue one: a child component that knows about the library and emits an event, and a parent that owns the form state.

Why a wrapper needs destroy()

The library creates its own <input> and suggestion list inside a container you give it. It also adds a click listener on document, so it can close the list when you click elsewhere.

When Vue removes your component (a v-if, a route change, a closed modal), it removes the container and the input. It doesn't know about the listener on document. That one stays, and it keeps the old field instance in memory.

We measured it in Chrome: one field on screen, unmounted and mounted again 5 times.

Bar chart: click listeners left on document after 5 unmount/mount cycles. Without destroy() in version 3.1.0: 6. Version 1.5.1, which has no destroy(): 6. With destroy() in onBeforeUnmount: 1

Setup Click listeners on document after 5 cycles
geocoder-autocomplete 3.1.0, no destroy() 6
geocoder-autocomplete 1.5.1 (has no destroy()) 6
geocoder-autocomplete 3.1.0, destroy() in onBeforeUnmount 1 (the live field)

Five leaked listeners won't crash a page. In a single-page app where the address form opens in a modal many times a session, they add up. The library's README says it plainly: call destroy() before removing the host page or framework component. destroy() also cancels requests that are still running.

Step 1: Load Vue and the library

The demo runs without a build step, so everything comes from a CDN, with exact versions:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@geoapify/geocoder-autocomplete@3.1.0/styles/minimal.css"> <script src="https://cdn.jsdelivr.net/npm/vue@3.5.46/dist/vue.global.prod.js"></script> <script src="https://cdn.jsdelivr.net/npm/@geoapify/geocoder-autocomplete@3.1.0/dist/index.min.js"></script> 

The browser build of the library exposes a global autocomplete with the class autocomplete.GeocoderAutocomplete. The library also ships three more themes: minimal-dark, round-borders and round-borders-dark.

Step 2: The AddressAutocomplete component

The component gets a container through a template ref, creates the field once the container exists, and passes the selected place up as a select event.

const { ref, onMounted, onBeforeUnmount } = Vue; const AddressAutocomplete = { props: { apiKey: { type: String, required: true }, options: { type: Object, default: () => ({}) } }, emits: ["select"], setup(props, { emit }) { const container = ref(null); let field = null; onMounted(() => { // The library creates its own <input> inside the container. field = new autocomplete.GeocoderAutocomplete(container.value, props.apiKey, props.options); // `place` is a GeoJSON Feature, or null when the user clears the field. field.on("select", (place) => emit("select", place)); }); // Removes the listeners and markup the library added. onBeforeUnmount(() => { if (field) field.destroy(); }); return { container }; }, template: `<div ref="container" class="autocomplete-container"></div>` }; 

Two details matter:

  • onMounted, not setup() itself. In setup() the template ref is still null, and the constructor needs a real element.
  • position: relative on the container. The suggestion list is positioned against it; without it the list opens in the wrong place.
.autocomplete-container { position: relative; } 

The options are passed straight to the library. These are the ones the demo uses:

Option Value What it does
placeholder "Start typing an address" placeholder of the generated input
skipIcons true no icons in the suggestion list
allowNonVerifiedHouseNumber true keep a house number the user typed even if it's not in the map data
allowNonVerifiedStreet true the same for the street

Other useful ones: lang, limit, filter and bias (for example, only one country, or results near the user first). All are listed in the library docs.

Step 3: Fill a v-model form from the selected address

The parent keeps the address in a reactive object, binds each input with v-model, and copies the parts of the selected place into it.

const { reactive } = Vue; const App = { components: { AddressAutocomplete }, setup() { const address = reactive({ street: "", housenumber: "", postcode: "", city: "", state: "", country: "" }); function onAddressSelect(place) { if (!place) return; // field cleared: keep what the user typed const p = place.properties; address.street = p.street || ""; address.housenumber = p.housenumber || ""; address.postcode = p.postcode || ""; address.city = p.city || p.town || p.village || ""; address.state = p.state || ""; address.country = p.country || ""; } return { apiKey: "YOUR_API_KEY", address, onAddressSelect }; }, template: ` <address-autocomplete :api-key="apiKey" @select="onAddressSelect"></address-autocomplete> <input v-model="address.street"> <input v-model="address.housenumber"> <input v-model="address.postcode"> <input v-model="address.city"> <input v-model="address.state"> <input v-model="address.country"> ` }; Vue.createApp(App).mount("#app"); 

The library calls the Geoapify Address Autocomplete API as the user types, and the selected result has the address already split into parts. The town and village fallbacks are a safety net in case a result has no city.

Does the mapping hold outside the US? We typed six addresses in six countries:

Table of live Autocomplete API results for six addresses in the United States, Germany, France, Spain and Austria, all with street, housenumber, postcode, city, state and country filled; the Bar Harbor postcode 04609 is highlighted

Typed street housenumber postcode city state country
350 5th Ave, New York 5th Avenue 350 10118 New York New York United States
1 Main Street, Bar Harbor Main Street 1 04609 Bar Harbor Maine United States
Unter den Linden 1, Berlin Unter den Linden 1 10117 Berlin Berlin Germany
Rue de Rivoli 99, Paris Rue de Rivoli 99 75001 Paris Ile-de-France France
Plaza Mayor 1, Madrid Plaza Mayor 1 28012 Madrid Community of Madrid Spain
Seestrasse 99, Hallstatt Seestraße 99 4830 Hallstatt Upper Austria Austria

The formatted line changes order by country ("350 5th Avenue" in New York, "Unter den Linden 1" in Berlin). The properties don't, so the form code needs no per-country logic.

One thing to keep: postcodes are strings. Bar Harbor's 04609 turns into 4609 if you store it as a number.

The same component in a Vite project

With a build step, install the library and import it instead of using the global:

npm install @geoapify/geocoder-autocomplete 
<!-- AddressAutocomplete.vue --> <script setup> import { ref, onMounted, onBeforeUnmount } from "vue"; import { GeocoderAutocomplete } from "@geoapify/geocoder-autocomplete"; import "@geoapify/geocoder-autocomplete/styles/minimal.css"; const props = defineProps({ apiKey: { type: String, required: true }, options: { type: Object, default: () => ({}) } }); const emit = defineEmits(["select"]); const container = ref(null); let field = null; onMounted(() => { field = new GeocoderAutocomplete(container.value, props.apiKey, props.options); field.on("select", (place) => emit("select", place)); }); onBeforeUnmount(() => { field?.destroy(); }); </script> <template> <div ref="container" class="autocomplete-container"></div> </template> <style scoped> .autocomplete-container { position: relative; } </style> 

Use it as <AddressAutocomplete api-key="YOUR_API_KEY" @select="onAddressSelect" />. We built this exact file with Vite 8 and Vue 3.5.46 and ran it in Chrome: the Berlin address filled all six fields.

Let an AI assistant write it

Do you need to type this yourself? We gave the task to an AI coding assistant (Claude) twice, each time in a fresh session without web access, and ran both pages with a real API key.

Prompt 1, vague:

Add Geoapify address autocomplete to a Vue 3 app that fills an address form. Give me one HTML file I can open in the browser.

Page written by an AI assistant from the vague prompt: a shipping address form filled with 350 5th Avenue, New York, 10118, United States and latitude/longitude, built on geocoder-autocomplete 1.5.1, with notes: extra Place Details request per selection, no destroy(), street and house number in one field

It works: suggestions appear and the form fills in. But look under the hood:

  • It loaded @geoapify/geocoder-autocomplete@1.5.1, released in November 2022. The current version is 3.1.0. The assistant said itself that the version came "from memory".
  • With 1.5.1, every selection sends a second request to the Place Details API. Version 3 skips it unless you turn on addDetails.
  • 1.5.1 has no destroy(). The page removes its own select handler on unmount, but the document listener stays (the 1.5.1 row in the chart above).
  • Street and house number end up in one field ("350 5th Avenue").

Prompt 2, precise:

Build a single HTML file (no build step) with a Vue 3 address form that uses Geoapify address autocomplete.

  • Load Vue 3.5.46 and @geoapify/geocoder-autocomplete 3.1.0 from jsDelivr: dist/index.min.js (global autocomplete, class autocomplete.GeocoderAutocomplete(container, apiKey, options)) and styles/minimal.css. There is no official Vue wrapper; write your own component.
  • Component AddressAutocomplete: props apiKey and options, emits select. Create the field in onMounted on a container div from a template ref. Forward field.on('select', place => …) (place is a GeoJSON Feature, or null when cleared). Call field.destroy() in onBeforeUnmount. The container needs position: relative.
  • Parent: a reactive address with street, housenumber, postcode, city, state, country, each bound with v-model. On select, copy those properties (city falls back to town, then village). Ignore null.
  • Options: placeholder "Start typing an address", skipIcons: true, allowNonVerifiedHouseNumber: true, allowNonVerifiedStreet: true.
  • Show the form state as JSON under the form.

Page written by an AI assistant from the precise prompt: an address form with separate street and house number fields filled from the Empire State Building result, built on Vue 3.5.46 and geocoder-autocomplete 3.1.0 with destroy() in onBeforeUnmount

This is the same component as the hand-written demo: the right versions, onMounted, destroy(), and six separate fields. The one flaw was cosmetic: the clear button sat just outside the input.

What made the difference:

  • The version. Without one, the assistant reached for a version it remembered, two major versions old. Name the exact version, and the CDN path if you don't use npm.
  • "There is no Vue wrapper." One line stops the assistant from looking for a package that doesn't exist and tells it to write the component.
  • The lifecycle. onMounted for creation and destroy() in onBeforeUnmount. Neither is Vue-specific knowledge the assistant lacks. It just doesn't add cleanup it wasn't asked for.
  • The fields you want. Separate street and house number, the city fallbacks, and what to do on null. An assistant can't guess your form.

Building an AI agent instead of a form? The Geoapify MCP server gives agents geocoding tools directly, so an agent can turn "350 5th Ave, New York" into a structured address without writing a request.

Summary

  • You don't need a Vue package for Geoapify autocomplete. Wrap the plain library in a component: create it in onMounted, emit select, call destroy() in onBeforeUnmount.
  • Without destroy(), every unmount leaves a listener on document (6 instead of 1 after 5 remounts in our test).
  • The selected result has street, housenumber, postcode, city, state and country in every country we tried. Keep postcodes as strings.
  • With npm and Vite, the same component is one .vue file with two imports.
  • AI assistants can write it, but a vague prompt can get you an old library version and no cleanup. Name the version, the lifecycle hooks and the fields.

FAQ

Is there an official Vue component for Geoapify autocomplete?
No. There's @geoapify/geocoder-autocomplete (plain JavaScript) and @geoapify/react-geocoder-autocomplete for React. In Vue, wrap the plain library in your own component as shown above.

Why create the autocomplete in onMounted and not in setup()?
The library needs a real DOM element to put its input into. A template ref is null until the component is mounted.

Do I really need destroy()?
Yes, if the component can be removed while the page stays: v-if, routes, modals, tabs. Without it, a listener on document and the old instance stay in memory every time.

How do I limit suggestions to one country?
Pass a filter in the options, for example filter: { countrycode: ["us"] }, or call field.addFilterByCountry(["us"]). bias options rank results near a point first without excluding others.

Can I get the coordinates of the selected address?
Yes. place is a GeoJSON Feature: place.geometry.coordinates is [lon, lat], and place.properties.lat / lon have the same values.

What if a result has no city?
All six addresses we tried had one, even the small Austrian village of Hallstatt. The fallback p.city || p.town || p.village is a safety net, and the field stays editable, so the user can always type the city.

Does it work with Nuxt?
Create the field in onMounted (it runs only in the browser) or wrap the component in <ClientOnly>, because the library needs document.

Try it

Get a free API key at myprojects.geoapify.com and try it in your own form. How do you handle addresses in your Vue apps: one field, a full form, or both? Tell us in the comments.