# what3words developer documentation: Display Map > Show what3words addresses and the 3 metre square grid on a map: map components for Android, iOS and the web, and the grid on Google Maps, Mapbox, Leaflet and Bing Maps. Every page in this section, in menu order, as Markdown. Section page: https://developer.what3words.com/docs/display-map.md. All sections: https://developer.what3words.com/llms.txt --- # Using the Android Map Component Displaying the what3words grid and marker on Google Maps or Mapbox new or existing map applications. Topics: Android, Mobile App Section: [Display Map](https://developer.what3words.com/docs/display-map.md) Source: https://developer.what3words.com/tutorial/using-the-android-map-component Updated: 2026-11-27 ### Tutorial ### Introduction The easiest way to add what3words to your technology is to use one of our components. We have several components available for JavaScript, iOS, and Android which require minimal development to integrate. The what3words Android Map Component provides a straightforward way to add a what3words grid on top of Google Maps or Mapbox map, displaying the what3words address and marker on the map for a selected 3 word address. This tutorial steps through how our Android Map Component can be added to a new project that requires creating a map from scratch or to an existing map: - If you are creating a new map from scratch using our Map component then we recommend using our map fragments: [W3WGoogleMapFragment](https://github.com/what3words/w3w-android-map-components/tree/main?tab=readme-ov-file#enable-what3words-features-in-an-new-google-maps-app-using-w3wgooglemapfragment) or [W3WMapboxMapFragment](https://github.com/what3words/w3w-android-map-components/tree/main?tab=readme-ov-file#enable-what3words-features-in-an-new-mapbox-maps-app-using-w3wmapboxmapfragment) if the map provider is respectively Google Maps or MapBox; - If you want to add what3words to an existing map then we recommend using our map wrappers: [W3WGoogleMapsWrapper](https://github.com/what3words/w3w-android-map-components/tree/main?tab=readme-ov-file#enable-what3words-features-in-an-existing-google-maps-app-using-W3WGoogleMapsWrapper) or [W3WMapBoxWrapper](https://github.com/what3words/w3w-android-map-components/tree/main?tab=readme-ov-file#enable-what3words-features-in-an-existing-mapbox-maps-app-using-w3wmapboxwrapper) if the map provider is respectively Google Maps or MapBox. Follow the steps below to select your chosen way to integrate our what3words map component into your project. GitHub repo: [https://github.com/what3words/w3w-android-map-components](https://github.com/what3words/w3w-android-map-components) ### Quickstart The Android Map Component requires just a few lines of code to be added to an android application to create a map with what3words functionality. - Replace `YOUR-API-KEY` with your what3words API key and any `map provider API key` that you would like to use on your project, e.g. GOOGLE MAPS or MAPBOX API keys. - It is compatible with applications that are built using `Android SDK 23 or higher`. Here are listed some sample apps that can be used: - [Google Maps Sample App](https://github.com/what3words/w3w-android-samples/tree/main/maps-googlemaps-sample) - [MapBox Sample App](https://github.com/what3words/w3w-android-samples/tree/main/mapbox-sample) ![android\_map\_component\_final\_result](https://kpcwlqbjuaezxoatdmqy.supabase.co/storage/v1/object/public/devsite-media/wp/b8d74fd2e43b389621e08ff4907dc94861569bed3f724919b7d926d93c561170.w1600.webp) **Kotlin** ```kotlin class MainActivity : AppCompatActivity(), W3WGoogleMapFragment.OnMapReadyCallback { private lateinit var binding: ActivityMapsBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMapsBinding.inflate(layoutInflater) setContentView(binding.root) val mapFragment = supportFragmentManager .findFragmentById(R.id.map) as W3WGoogleMapFragment mapFragment.apiKey("YOUR_API_KEY_HERE", this) // add AutoSuggest Component to the Map Component binding.autosuggest.apiKey("YOUR_API_KEY_HERE") .returnCoordinates(true) .onSuggestionSelected { square -> if (square != null) { map.selectAtSquare(square) } else { map.unselect() } } } override fun onMapReady(map: W3WMap) { // add this to integrate the AutoSuggest Component this.map = map map.addMarkerAtCoordinates(lat: 51.5209894, lng: -0.1956749, markerColor = W3WMarkerColor.YELLOW) map.onSquareSelected( onSuccess = { square, _, _ -> // add this to bind the AutoSuggest Component to the Map Component binding.autosuggest.display(square) Snackbar.make(binding.root, square.words, Snackbar.LENGTH_INDEFINITE).show() } ) } } ``` ### Step by Step ## 1. Get API key You will need a what3words API key to complete this tutorial. [Get an API Key](https://accounts.what3words.com/select-plan) or [sign in](https://accounts.what3words.com/). ## 2. Get Google API key You also will need to get a [Google API key](https://developers.google.com/maps/documentation/places/web-service/get-api-key#console) or [Mapbox API key](https://docs.mapbox.com/android/maps/guides/install/) for your chosen map provider. ## 3. Add the dependency Open your project in Android Studio Open up your module-level `build.gradle` file. Make sure that your project’s `minSdkVersion` is at API 23 or higher. **Kotlin** ```kotlin android { ... defaultConfig { minSdkVersion 23 } } ``` Under dependencies, add a new build rule for the latest what3words Android Map Component. **Kotlin** ```kotlin dependencies { implementation 'com.what3words:w3w-android-map-components:1.0.1' } ``` Add this snippet to the `build.gradle` file (app level) **Kotlin** ```kotlin compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } ``` Add also the following `proguard rules` **Kotlin** ```kotlin -keep class com.what3words.javawrapper.request.* { *; } -keep class com.what3words.javawrapper.response.* { *; } ``` Because you’ve edited your Gradle files, Android Studio will ask you whether you want to sync the Gradle files. You can sync now. To perform network operations in your application, your manifest `AndroidManifest.xml` file must include the following permissions: **Kotlin** ```kotlin ... ``` ## 4. New app with Google Maps If you are starting a new project and you are creating a new app from scratch, we recommend using our `W3WGoogleMapFragment`. The main advantage is that all the required events to draw the grid are done under the hood, resulting in less boilerplate code and still having access to Google Maps to apply standard customisation (i.e. map types, etc.). To use the what3words Google Maps Fragment in your app, first, follow the quick start tutorial on the [Google developer portal here](https://developers.google.com/maps/documentation/android-sdk/start). This ensures that Google Maps can be used with the what3words Map Fragment. After a successful Google Maps run, you can start using our `W3WGoogleMapFragment` following these steps. Add the following line of code to your `activity_main.xml` file within the `res` folder of your application: **Kotlin** ```kotlin ``` Add what3words Google Maps Fragment to your `MapsActivity.kt` file. You will need to add your [what3words API key](https://what3words.com/select-plan?referrer=/tutorial/using-the-web-map-component) here to display the Map Fragment. **Note:** After adding this snippet run your application and you will display Google Maps with the what3words grid on top of it. **Kotlin** ```kotlin class MainActivity : AppCompatActivity(), W3WGoogleMapFragment.OnMapReadyCallback { private lateinit var binding: ActivityMapsBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMapsBinding.inflate(layoutInflater) setContentView(binding.root) val mapFragment = supportFragmentManager .findFragmentById(R.id.map) as W3WGoogleMapFragment mapFragment.apiKey("YOUR_API_KEY_HERE", this) } override fun onMapReady(map: W3WMap) { } } ``` ### Customise the Map Component The Map Component can be customised using some what3words properties. Here is shown an example where you can add a simple market to your Map with a specified what3words address ![customise\_map\_component](https://kpcwlqbjuaezxoatdmqy.supabase.co/storage/v1/object/public/devsite-media/wp/c2c63a3106c0e2de686c01f14f0d55211e61c977974520f57f3b34fd45be5083.w1600.webp) **Kotlin** ```kotlin class MainActivity : AppCompatActivity(), W3WGoogleMapFragment.OnMapReadyCallback { private lateinit var binding: ActivityMapsBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMapsBinding.inflate(layoutInflater) setContentView(binding.root) val mapFragment = supportFragmentManager .findFragmentById(R.id.map) as W3WGoogleMapFragment mapFragment.apiKey("YOUR_API_KEY_HERE", this) } override fun onMapReady(map: W3WMap) { // set a marker with a specified what3words address map.addMarkerAtWords("filled.count.soap") } } ``` You can set a language to get all the 3wa in the desired language (default English) by adding this line of code within the `onMapReady` function: **Kotlin** ```kotlin class MainActivity : AppCompatActivity(), W3WGoogleMapFragment.OnMapReadyCallback { private lateinit var binding: ActivityMapsBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMapsBinding.inflate(layoutInflater) setContentView(binding.root) val mapFragment = supportFragmentManager .findFragmentById(R.id.map) as W3WGoogleMapFragment mapFragment.apiKey("YOUR_API_KEY_HERE", this) } override fun onMapReady(map: W3WMap) { //set language to get all the what3words addresses in the desired language (default english) map.setLanguage("en") map.addMarkerAtWords("filled.count.soap") } } ``` You can make the map marker change color or their zoom level or add a list of specified what3words addresses. **Note:** the default colour of the marker is the brand’s red. ![multiple\_markers](https://kpcwlqbjuaezxoatdmqy.supabase.co/storage/v1/object/public/devsite-media/wp/3630b63f53b7a4e7926971dbd33c87dd10e5649ff7334311f06ac1fc4e22747d.w1600.webp) **Kotlin** ```kotlin class MainActivity : AppCompatActivity(), W3WGoogleMapFragment.OnMapReadyCallback { private lateinit var binding: ActivityMapsBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMapsBinding.inflate(layoutInflater) setContentView(binding.root) val mapFragment = supportFragmentManager .findFragmentById(R.id.map) as W3WGoogleMapFragment mapFragment.apiKey("YOUR_API_KEY_HERE", this) } override fun onMapReady(map: W3WMap) { map.setLanguage("en") // an example on how to add a blue marker on a valid 3 word address and move the map view(camera) to the added marker map.addMarkerAtWords( listOf("filled.count.soap","stop.vibrates.looked"), markerColor = W3WMarkerColor.TURQUOISE, zoomOption = W3WZoomOption.CENTER_AND_ZOOM ) } } ``` You can add a map marker using coordinates instead of the what3words address. **Kotlin** ```kotlin class MainActivity : AppCompatActivity(), W3WGoogleMapFragment.OnMapReadyCallback { private lateinit var binding: ActivityMapsBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMapsBinding.inflate(layoutInflater) setContentView(binding.root) val mapFragment = supportFragmentManager .findFragmentById(R.id.map) as W3WGoogleMapFragment mapFragment.apiKey("YOUR_API_KEY_HERE", this) } override fun onMapReady(map: W3WMap) { // set a marker using coordinates map.addMarkerAtCoordinates(51.5209894, -0.1956749, markerColor = W3WMarkerColor.YELLOW) } } ``` ### Access the map instance To access the Google map instance inside the Google Map Fragment you will need to add this line of code to your application: **Kotlin** ```kotlin class MainActivity : AppCompatActivity(), W3WGoogleMapFragment.OnMapReadyCallback { private lateinit var binding: ActivityMapsBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMapsBinding.inflate(layoutInflater) setContentView(binding.root) val mapFragment = supportFragmentManager .findFragmentById(R.id.map) as W3WGoogleMapFragment mapFragment.apiKey("YOUR_API_KEY_HERE", this) } override fun onMapReady(map: W3WMap) { map.addMarkerAtCoordinates(51.5209894, -0.1956749, markerColor = W3WMarkerColor.YELLOW) //if you want to access the google map instance inside W3WGoogleMapFragment do the following (map as? W3WGoogleMapFragment.Map)?.googleMap()?.let { googleMap -> googleMap.mapType = GoogleMap.MAP_TYPE_NORMAL } } } ``` Here is what your application should look like: ![marker\_with\_coordinates](https://kpcwlqbjuaezxoatdmqy.supabase.co/storage/v1/object/public/devsite-media/wp/6105936b433c0c3ffc91447c24a9bdcdb76ffcfe7b5a8bb50eac7a6e8e20e405.w1600.webp) ### Listening for events Now when you click on the map marker you can display the what3words address if you trigger the `onSquareSelected` event. **Note:** Only one square can be selected at the same time, just like our core apps. **Kotlin** ```kotlin class MainActivity : AppCompatActivity(), W3WGoogleMapFragment.OnMapReadyCallback { private lateinit var binding: ActivityMapsBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMapsBinding.inflate(layoutInflater) setContentView(binding.root) val mapFragment = supportFragmentManager .findFragmentById(R.id.map) as W3WGoogleMapFragment mapFragment.apiKey("YOUR_API_KEY_HERE", this) } override fun onMapReady(map: W3WMap) { map.addMarkerAtCoordinates(51.5209894, -0.1956749, markerColor = W3WMarkerColor.YELLOW) // set up a a callback for when an square in the map is selected map.onSquareSelected( onSuccess = { square, _, _ -> Snackbar.make(binding.root, square.words, Snackbar.LENGTH_INDEFINITE).show() } ) } } ``` ### Use AutoSuggest Component in the Search field If you want to add the AutoSuggest Component to the search box on top of the Map Fragment, you need to update the `activity_maps.xml` to both have the what3words components, the `W3WAutosuggestEditText` (for the AutoSuggest Component) and `W3WGoogleMapFragment` (for the Map Component). **Kotlin** ```kotlin ``` Now you need to set up the what3words AutoSuggest component with your API KEY to return coordinates so you can integrate it into the Map component without extra API calls. **Note:** As it is set up on our core app, you will be able to set that up when a suggestion is selected from the AutoSuggest Component it will select a what3words address on the map. **Kotlin** ```kotlin class MainActivity : AppCompatActivity(), W3WGoogleMapFragment.OnMapReadyCallback { private lateinit var binding: ActivityMapsBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMapsBinding.inflate(layoutInflater) setContentView(binding.root) val mapFragment = supportFragmentManager .findFragmentById(R.id.map) as W3WGoogleMapFragment mapFragment.apiKey("YOUR_API_KEY_HERE", this) // add AutoSuggest Component to the Map Component binding.autosuggest.apiKey("YOUR_API_KEY_HERE") .returnCoordinates(true) .onSuggestionSelected { square -> if (square != null) { map.selectAtSquare(square) } else { map.unselect() } } } override fun onMapReady(map: W3WMap) { // add this to integrate the AutoSuggest Component this.map = map map.addMarkerAtCoordinates(lat: 51.5209894, lng: -0.1956749, markerColor = W3WMarkerColor.YELLOW) map.onSquareSelected( onSuccess = { square, _, _ -> // add this to bind the AutoSuggest Component to the Map Component binding.autosuggest.display(square) Snackbar.make(binding.root, square.words, Snackbar.LENGTH_INDEFINITE).show() } ) } } ``` Here is what your application should look like: ![android\_map\_component\_final\_result](https://kpcwlqbjuaezxoatdmqy.supabase.co/storage/v1/object/public/devsite-media/wp/b8d74fd2e43b389621e08ff4907dc94861569bed3f724919b7d926d93c561170.w1600.webp) ### Select Map Provider Our Map Component can support different map service providers, such as Google Maps and Mapbox. By simply replacing the Google Map fragment used in the examples above `W3WGoogleMapFragment` with the Mapbox Map Fragment `W3WMapboxMapFragment` in your `activity_main.xml` and `MapsActivity.kt` files. **Note:** To use the what3words Mapbox Maps Fragment in your app, first follow the quick start tutorial on the [Mapbox developer portal here](https://docs.mapbox.com/android/navigation/guides/get-started/install/). This ensures that Mapbox Maps can be used with the what3words Fragment. ## 5. Existing app with Google Maps If you already have an application we recommend using our what3words Google Map Wrapper in your app. To get started first follow the quick start tutorial on the [Google developer portal here](https://developers.google.com/maps/documentation/android-sdk/start). This ensures that Google Maps can be used with the what3words Map Wrapper. After a successful Google Maps run, you can start using our `W3WGoogleMapWrapper` following these steps: Add the following line of code to your `activity_main.xml` file within the `res` folder of your application: **Kotlin** ```kotlin ``` Add what3words Google Maps Wrapper to your `MapsActivity.kt` file. You will need to add your what3words API key here to display the Map Wrapper. **Kotlin** ```kotlin class MainActivity : AppCompatActivity(), OnMapReadyCallback { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val mapFragment = supportFragmentManager .findFragmentById(R.id.map) as SupportMapFragment mapFragment.getMapAsync(this) } override fun onMapReady(map: GoogleMap) { val apiWrapper = What3WordsV3("YOUR_API_KEY_HERE", this) val googleMapsWrapper = W3WGoogleMapsWrapper( this, map, apiWrapper ) } } ``` After adding this snippet run your application and you will display Google Maps with the what3words grid on top of it. ### Customise the Map Component The Map Component can be customised using some what3words properties. Here is shown an example where you can - add a simple market to your Map with a specified what3words address; - set your own zoom level; - set the language of the what3words addresses; **Kotlin** ```kotlin class MainActivity : AppCompatActivity(), OnMapReadyCallback { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val mapFragment = supportFragmentManager .findFragmentById(R.id.map) as SupportMapFragment mapFragment.getMapAsync(this) } override fun onMapReady(map: GoogleMap) { val apiWrapper = What3WordsV3("YOUR_API_KEY_HERE", this) val googleMapsWrapper = W3WGoogleMapsWrapper( this, map, apiWrapper ).setLanguage("en") // set the language of the what3words addresses //show an example on how to add a blue marker //on a valid 3 word address and move the camera to the added marker. googleMapsWrapper.addMarkerAtWords( "filled.count.soap", markerColor.BLUE, { marker -> val cameraPosition = CameraPosition.Builder() .target(LatLng(marker.coordinates.lat, marker.coordinates.lng)) .zoom(19f) .build() p0.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)) }, { error -> Log.e("MainActivity", "${error.message}") } ) } } ``` ### Listening for events Using an event listener, it is possible to fire other functionality in an app when something changes in the Map Component. For example, it is possible to listen for when a square on the grid map has been selected by the users or to listen for when new coordinates have been returned and pan/zoom a map to the location. **Kotlin** ```kotlin class MainActivity : AppCompatActivity(), OnMapReadyCallback { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val mapFragment = supportFragmentManager .findFragmentById(R.id.map) as SupportMapFragment mapFragment.getMapAsync(this) } override fun onMapReady(map: GoogleMap) { val apiWrapper = What3WordsV3("YOUR_API_KEY_HERE", this) val googleMapsWrapper = W3WGoogleMapsWrapper( this, map, apiWrapper ) //example how to add a blue marker on a valid 3 word address and move camera to the added marker. googleMapsWrapper.addMarkerAtWords( "filled.count.soap", markerColor.BLUE, { marker -> val cameraPosition = CameraPosition.Builder() .target(LatLng(marker.coordinates.lat, marker.coordinates.lng)) .zoom(19f) .build() p0.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)) }, { error -> Log.e("MainActivity", "${error.message}") } ) //Using an event listener → click on existing what3words markers on the map. w3wMapsWrapper.onMarkerClicked { marker -> Log.i("MainActivity", "clicked: ${marker.words}") } //REQUIRED map.setOnCameraIdleListener { //existing code here... //needed to draw the 3x3m grid on the map googleMapsWrapper.updateMap() } //REQUIRED map.setOnCameraMoveListener { //existing code here... //needed to draw the 3x3m grid on the map googleMapsWrapper.updateMove() } } } ``` ### Set coordinates per selected marker Here is an example of how to select a 3x3m what3words square using coordinates: **Kotlin** ```kotlin class MainActivity : AppCompatActivity(), OnMapReadyCallback { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val mapFragment = supportFragmentManager .findFragmentById(R.id.map) as SupportMapFragment mapFragment.getMapAsync(this) } override fun onMapReady(map: GoogleMap) { val apiWrapper = What3WordsV3("YOUR_API_KEY_HERE", this) val googleMapsWrapper = W3WGoogleMapsWrapper( this, map, apiWrapper ) … map.setOnMapClickListener { latLng -> //existing code here... //example of how to select a 3x3m what3words square using lat/lng googleMapsWrapper.selectAtCoordinates(latLng.latitude, latLng.longitude) } } } ``` ## 6. Existing app with Mapbox If you already have an application we recommend using our what3words Mapbox Wrapper in your app. To get started first follow the quick start tutorial on the [Mapbox developer portal here](https://docs.mapbox.com/android/navigation/guides/get-started/install/). This ensures that Mapbox can be used with the what3words Map Wrapper. After a successful Google Maps run, you can start using our `W3WMapboxWrapper` following these steps. Add the following line of code to your `activity_main.xml` file within the `res` folder of your application: **Kotlin** ```kotlin ``` Add what3words Mapbox Wrapper to your `MapsActivity.kt` file. You will need to add your what3words API key here to display the Map Wrapper. **Kotlin** ```kotlin class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) binding.mapView.getMapboxMap().loadStyleUri(Style.MAPBOX_STREETS) setContentView(binding.root) val wrapper = What3WordsV3("YOUR_API_KEY_HERE", this) val mapboxWrapper = W3WMapBoxWrapper( this, binding.mapView.getMapboxMap(), wrapper, ) } } ``` After adding this snippet run your application and you will display the Mapbox with the what3words grid on top of it. ### Customise the Map Component The Map Component can be customised using some what3words properties. Here is shown an example where you can - add a simple market to your Map with a specified what3words address; - set your own zoom level; - set the language of the what3words addresses; **Kotlin** ```kotlin class MainActivity: AppCompatActivity() { private lateinit var binding: ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) binding.mapView.getMapboxMap().loadStyleUri(Style.MAPBOX_STREETS) setContentView(binding.root) val wrapper = What3WordsV3("YOUR_API_KEY_HERE", this) val mapboxWrapper = W3WMapBoxWrapper( this, binding.mapView.getMapboxMap(), wrapper, ).setLanguage("en") // set the language of the what3words addresses //show an example on how to add a blue marker //on a valid 3 word address and move the camera to the added marker. mapboxWrapper.addMarkerAtWords( "filled.count.soap", markerColor.BLUE, { marker -> }, { error -> Log.e("MainActivity", "${error.message}") } ) } } ``` ### Listening for events Using an event listener, it is possible to fire other functionality in an app when something changes in the Map Component. For example, it is possible to listen for when a square on the grid map has been selected by the users or to listen for when new coordinates have been returned and pan/zoom a map to the location. **Kotlin** ```kotlin class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) binding.mapView.getMapboxMap().loadStyleUri(Style.MAPBOX_STREETS) setContentView(binding.root) val wrapper = What3WordsV3("YOUR_API_KEY_HERE", this) val mapboxWrapper = W3WMapBoxWrapper( this, binding.mapView.getMapboxMap(), wrapper, ).setLanguage("en") // set the language of the what3words addresses //show an example on how to add a blue marker //on a valid 3 word address and move the camera to the added marker. mapboxWrapper.addMarkerAtWords( "filled.count.soap", markerColor.BLUE, { marker -> }, { error -> Log.e("MainActivity", "${error.message}") } ) //Using an event listener → click on existing what3words markers on the map. mapboxWrapper.onMarkerClicked { Log.i("MainActivity", "clicked: ${it.words}") } //REQUIRED binding.mapView.getMapboxMap().addOnMapIdleListener { //existing code here... //needed to draw the 3x3m grid on the map mapboxWrapper.updateMap() } //REQUIRED binding.mapView.getMapboxMap().addOnCameraChangeListener { //existing code here... //needed to draw the 3x3m grid on the map mapboxWrapper.updateMove() } } } ``` ### Set coordinates per selected marker Here is an example of how to select a 3x3m what3words square using coordinates: **Kotlin** ```kotlin class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) binding.mapView.getMapboxMap().loadStyleUri(Style.MAPBOX_STREETS) setContentView(binding.root) val wrapper = What3WordsV3("YOUR_API_KEY_HERE", this) val mapboxWrapper = W3WMapBoxWrapper( this, binding.mapView.getMapboxMap(), wrapper, ).setLanguage("en") // set the language of the what3words addresses //show an example on how to add a blue marker //on a valid 3 word address and move the camera to the added marker. mapboxWrapper.addMarkerAtWords( "filled.count.soap", markerColor.BLUE, { marker -> }, { error -> Log.e("MainActivity", "${error.message}") } ) ... binding.mapView.getMapboxMap().addOnMapClickListener { latLng -> //existing code here... //example of how to select a 3x3m what3words square using lat/lng mapboxWrapper.selectAtCoordinates(latLng.latitude(), latLng.longitude()) true } } } ``` ## 7. Configuring for use with API server If you run our Enterprise Suite API Server yourself, you may specify the URL to your own server by adding this line of code to the Map Component: **Kotlin** ```kotlin val wrapper = What3WordsV3("YOUR_API_KEY_HERE", "https://api.yourserver.com", this) ``` ## 8. Use library with Jetpack Compose Both Google Maps and Mapbox Wrapper and Fragment work with Jetpack Compose using `AndroidView` and `AndroidViewBinding`, these modules are all available in our [GitHub repository](https://github.com/what3words/w3w-android-samples/) as examples of usage of our `w3w-android-map-components` library in a Jetpack Compose app. ## 9. Map Component Functions | Method Name | Description | Example | | --- | --- | --- | | addMarkerAtCoordinates | This method allow you to add a marker/square to the map defined by the latitude and longitude provided. | addMarkerAtCoordinates(49.180803, -8.001330, { marker }, { error }) or add multiple Coordinates to the map: addMarkerAtCoordinates(listOf(Pair(49.180803, -8.001330), Pair(50.180803, -8.001330)), { markers }, { error }) Example: key=Your-API-Key | | addMarkerAtSuggestion | This method allow you to add a marker/square to the map after getting the what3words suggestion from our W3WAutosuggestEditText allowing easy integration between both components autosuggest and maps. | addMarkerAtSuggestion(suggestion, markerColor.RED, { marker }, { error }) or add multiple suggestions to the map: addMarkerAtSuggestion(suggestions, markerColor.RED, { markers }, { error }) | | addMarkerAtWords | This method allow you to add a marker/square to the map if the parameter is valid what3words address, e.g. filled.count.soap. If it's not valid, onError will be called returning APIResponse.What3WordsError.BAD\_WORDS. | addMarkerAtWords("filled.count.soap"), markerColor.RED, { marker }, { error }) or add multiple 3 word addresses to the map: addMarkerAtWords(listOf("filled.count.soap", "index.home.raft"), markerColor.RED, { markers }, { error }) | | findMarkerByCoordinates | findMarkerByCoordinates This method allow you to find a marker added to the map (returns null if no marker is added on the specified coordinates). | val marker = findMarkerByCoordinates(50.180803, -8.001330) | | getAllMarkers | This method allow you to get all added markers from the map. | val markers = getAllMarkers() | | getSelectedMarker | This method allow you to return a selected marker from the map. | val selected\_markers = getSelectedMarker() | | gridEnabled | This method allow you to enalbe the grid overlay over the map with all 3mx3m squares on the visible map bounds, enabled by default. | gridEnabled(true) | | handleZoomOption | \| handleZoomOption \| This method allow you to define the zoom options. \| handleZoomOption(latLng: LatLng, zoomOption: W3WZoomOption) \| | handleZoomOption(latLng: LatLng, zoomOption: W3WZoomOption) | | removeAllMarkers | This method allow you to remove all markers added to the map. | removeAllMarkers() | | removeMarkerAtCoordinates | This method allow you to remove a marker defined by coordinates from the map. | removeMarkerAtCoordinates(50.180803, -8.001330) or remove multiple markers at coordinates from the map: removeMarkerAtCoordinates(listOf(Pair(49.180803, -8.001330), Pair(50.180803, -8.001330)) | | removeMarkerAtSuggestion | removeMarkerAtSuggestion This method allow you to remove a marker defined by a what3words suggestion from the map. | removeMarkerAtSuggestion(suggestion) or remove multiple suggestions: removeMarkerAtSuggestion(suggestions) | | removeMarkerAtWords | This method allow you to remove a marker at what3words address from the map. | removeMarkerAtWords("filled.count.soap") or remove multiple markers at 3 word adresses from the map: removeMarkerAtWords(listOf("filled.count.soap", "index.home.raft")) | | selectAtCoordinates | This method allow you to set coordinates for a selected marker on the map. It can only have one selected marker at the time. | selectAtCoordinates(50.180803, -8.001330, { selectedMarker }, { error } | | selectAtSquare | This method allow you to set square for a selected marker on the map. It can only have one selected marker at the time. | selectAtSquare(square: SuggestionWithCoordinates, zoomOption: W3WZoomOption, onSuccess: Consumer?, onError: Consumer?) {} | | selectAtSuggestion | This method allow you to set suggestion for a selected marker on the map. It can only have one selected marker at the time. | selectAtSuggestion(suggestion, { selected marker }, { error }) | | selectAtWords | This method allow you to set 3 word address for a selected marker on the map. It can only have one selected marker at the time. | selectAtWords("filled.count.soap", { selectedMarker }, { error }) | | setGridColor | This method allow you to set a different color to the Grid when the background mode is dark or light. To be noted that map providers have different Dark/Light modes settings i.e: GoogleMaps sets dark mode using JSON styles but Mapbox has dark mode as a MapType. \[GridColor.AUTO\] - Will leave up to the library to decide which Grid color and selected square color to use to match some specific map types, i.e: use \[GridColor.DARK\] on normal map types, \[GridColor.LIGHT\] on Satellite and Traffic map types. \[GridColor.LIGHT\] - Will force grid and selected square color to be light. \[GridColor.DARK\] - Will force grid and selected square color to be dark. | setGridColor(gridColor: GridColor.LIGHT) | | setLanguage | This method allow you to set the default language for all the calls that the map makes to the API. The parameter should be a supported what3words address language as an ISO 639-1 2 letter code. Defaults to en (English). | setLanguage("en") | | unselect | This method allow you to remove the selected marker from the map. | unselect() | | updateMap | This method allow you to refresh the grid bounds and draw the grid. This method should be called on GoogleMap.setOnCameraIdleListener or MapboxMap.addOnMapIdleListener. Enabled is set to true (default)\* | updateMap()\* | | updateMove | This method allow you to swap from markers to squares and show/hide grid when zoom goes higher or lower than the zoom level threshold. This method should be called on GoogleMap.setOnCameraMoveListener or MapboxMap.addOnCameraChangeListener. Enabled is set to true (default)\* | updateMove()\* | ## 10. Events | Event | Description | Example | | --- | --- | --- | | onMarkerClicked | This method allow you to set up a callback for when an existing marker is clicked on the map. | onMarkerClicked { marker } | | onSquareSelected | This method allow you to set up a callback for when a square is selected either by clicking on the map or programmatically using any of \[selectAtWords\], \[selectAtCoordinates\], \[selectAtSuggestion\]. | map.onSquareSelected(onSuccess = { square, \_, \_ Snackbar.make(binding.root, square.words, Snackbar.LENGTH\_INDEFINITE).show()}) | ### Listening for events Using an event listener, it is possible to fire other functionality in an app when something changes in the Map Component. For example, when you click on the map marker you can display the what3words address if you trigger the `onSquareSelected` event. **Note:** Only one square can be selected at the same time, just like our core apps. **Kotlin** ```kotlin class MainActivity : AppCompatActivity() { private lateinit var binding: ActivityMainBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) binding.mapView.getMapboxMap().loadStyleUri(Style.MAPBOX_STREETS) setContentView(binding.root) val wrapper = What3WordsV3("YOUR_API_KEY_HERE", this) val mapboxWrapper = W3WMapBoxWrapper( this, binding.mapView.getMapboxMap(), wrapper, ).setLanguage("en") // set the language of the what3words addresses //show an example on how to add a blue marker //on a valid 3 word address and move the camera to the added marker. mapboxWrapper.addMarkerAtWords( "filled.count.soap", markerColor.BLUE, { marker -> }, { error -> Log.e("MainActivity", "${error.message}") } ) //Using an event listener → click on existing what3words markers on the map. mapboxWrapper.onMarkerClicked { Log.i("MainActivity", "clicked: ${it.words}") } //REQUIRED binding.mapView.getMapboxMap().addOnMapIdleListener { //existing code here... //needed to draw the 3x3m grid on the map mapboxWrapper.updateMap() } //REQUIRED binding.mapView.getMapboxMap().addOnCameraChangeListener { //existing code here... //needed to draw the 3x3m grid on the map mapboxWrapper.updateMove() } } } ``` ## 11. Troubleshooting If you encounter errors or issues related to convert-to-coordinate, convert-to-3wa and grid-section requests while using the Free plan, please check the network panel for the following error message `Error 402 payment required` and its response, indicating the need to upgrade to a higher plan: **JSON** ```json { "error": { "code": "QuotaExceeded", "message": "Quota exceeded or API plan does not have access to this feature. Please change your plan at https://accounts.what3words.com/select-plan, or contact support@what3words.com" } } ``` For more information, visit our [API plans page](https://accounts.what3words.com/select-plan). If you need further assistance, contact [support@what3words.com](mailto:support@what3words.com). --- # Displaying the what3words grid on a Google Map Adding a Google Map to your website with the what3words grid. Topics: JavaScript, Website Section: [Display Map](https://developer.what3words.com/docs/display-map.md) > [Display the what3words grid](https://developer.what3words.com/docs/display-map/display-the-what3words-grid.md) Source: https://developer.what3words.com/tutorial/displaying-the-what3words-grid-on-a-google-map Updated: 2026-11-27 ### Step by step The [what3words API](https://docs.what3words.com/api/v3/#grid) supports the ability to obtain a section of the 3m x 3m what3words grid in GeoJSON format, making it very simple to display on a map. This tutorial will show you how to integrate the what3words grid onto Google Maps. We also have tutorials demonstrating its use with both [Mapbox](https://docs.what3words.com/tutorials/grid-mapbox) and [LeafletJS](https://docs.what3words.com/tutorials/grid-leaflet.php). You will also need to sign up for a Google Maps developer account and be able to view other Google Maps tutorials at [https://developers.google.com/maps/documentation/javascript/tutorial](https://developers.google.com/maps/documentation/javascript/tutorial) ## 1. Get API key You will need a what3words API key to complete this tutorial. [Get an API Key](https://accounts.what3words.com/select-plan) or [sign in](https://accounts.what3words.com/). ## 2. Installation To load the JavaScript wrapper for the what3words API, use a `script` tag like the one in the following example. Replace `YOUR-API-KEY` with your what3words API key to get started. **Note:** We prefer to use a fixed version of the production version of your integrations. A specific version can also be specified within the script to ensure a predictable version of the component is loaded, for example`@5.0.0`. A log of versions can be found [here.](https://developer.what3words.com/tutorial/javascript-autosuggest-component#versioning) **JavaScript** ```javascript ``` The URL contained in the script tag is the location of a JavaScript file that loads everything you need for using the JavaScript wrapper for the what3words API. The `key` parameter contains your application’s API key. You will also need to load the Google Maps API, for example: **JavaScript** ```javascript ``` The bootstrap loader prepares the Maps JavaScript API for loading (no libraries are loaded until `importLibrary()` is called). The `key` parameter contains your [Google Maps API key](https://developers.google.com/maps/documentation/javascript/get-api-key). ## 3. Map style Within the `head` tag, we need to set style properties for the Google Map. In this example, we’ll set the map to display full screen. **JavaScript** ```javascript ``` ## 4. Map initialisation Within the `body` tag, we need to create a new div element to contain the map component. **JavaScript** ```javascript
``` This section shows you how to load the Maps JavaScript API into your web page and how to construct a new Google Maps object, and adds properties to the map including the center and zoom level. See the documentation for [other property options](https://developers.google.com/maps/documentation/javascript/reference#MapOptions). The `Map` library is loaded when the `initMap()` function is called. **JavaScript** ```javascript // Initialize and add the map let map; async function initMap() { const position = { lat: 51.52086, lng: -0.195499 }; // Request needed libraries. const { Map } = await google.maps.importLibrary("maps"); // The map, centered at Uluru map = new Map(document.getElementById("map"), { zoom: 19, center: position, mapId: "DEMO_MAP_ID" }); } initMap() ``` ## 5. Grid overlay The what3words grid can be displayed on top of a Google Map by passing GeoJSON data to the maps [Data](https://developers.google.com/maps/documentation/javascript/reference/data#Data.addGeoJson) object. Because only a segment of the grid section can be requested, we need to obtain a new grid section each time the map is panned or zoomed. **JavaScript** ```javascript // Initialize and add the map let map; async function initMap() { ... let gridData; // Add the what3words grid to the Google Map data layer once the desired zoom level is meet map.addListener("bounds_changed", function () { const zoom = map.getZoom(); const loadFeatures = zoom > 17; if (loadFeatures) { // Zoom level is high enough var ne = map.getBounds().getNorthEast(); var sw = map.getBounds().getSouthWest(); // Call the what3words Grid API to obtain the grid squares within the current visble bounding box what3words.api .gridSection({ boundingBox: { southwest: { lat: sw.lat(), lng: sw.lng() }, northeast: { lat: ne.lat(), lng: ne.lng() } }, format: "geojson" }) .then(function (data) { if (gridData !== undefined) { for (var i = 0; i < gridData.length; i++) { map.data.remove(gridData[i]); } } gridData = map.data.addGeoJson(data); }) .catch(console.error); } // Set the grid display style map.data.setStyle({ visible: loadFeatures, strokeColor: "#777", strokeWeight: 0.5 }); }); } initMap(); ``` ### Full example The example below takes the step by step guide and puts them into a complete, working example. **HTML** ```html Grid Section Map Overlay (Google Maps)
``` **CSS** ```css /* * style.css * Always set the map height explicitly to define the size of the div element * that contains the map. */ #map { height: 100%; } /* * Optional: Makes the sample page fill the window. */ html, body { height: 100%; margin: 0; padding: 0; } ``` **JavaScript** ```javascript // index.js // Initialize and add the map let map; async function initMap() { const position = { lat: 51.52086, lng: -0.195499 }; // Request needed libraries. const { Map } = await google.maps.importLibrary("maps"); // The map, centered at Uluru map = new Map(document.getElementById("map"), { zoom: 19, center: position, mapId: "DEMO_MAP_ID" }); let gridData; // Add the what3words grid to the Google Map data layer once the desired zoom level is meet map.addListener("bounds_changed", function () { const zoom = map.getZoom(); const loadFeatures = zoom > 17; if (loadFeatures) { // Zoom level is high enough var ne = map.getBounds().getNorthEast(); var sw = map.getBounds().getSouthWest(); // Call the what3words Grid API to obtain the grid squares within the current visble bounding box what3words.api .gridSection({ boundingBox: { southwest: { lat: sw.lat(), lng: sw.lng() }, northeast: { lat: ne.lat(), lng: ne.lng() } }, format: "geojson" }) .then(function (data) { if (gridData !== undefined) { for (var i = 0; i < gridData.length; i++) { map.data.remove(gridData[i]); } } gridData = map.data.addGeoJson(data); }) .catch(console.error); } // Set the grid display style map.data.setStyle({ visible: loadFeatures, strokeColor: "#777", strokeWeight: 0.5 }); }); } initMap(); ``` --- # Displaying the what3words grid on a LeafletJS Map Adding a LeafletJS Map to your website with the what3words grid. Topics: JavaScript, Website Section: [Display Map](https://developer.what3words.com/docs/display-map.md) > [Display the what3words grid](https://developer.what3words.com/docs/display-map/display-the-what3words-grid.md) Source: https://developer.what3words.com/tutorial/displaying-the-what3words-grid-on-a-leafletjs-map Updated: 2026-11-27 ### Step by step The [what3words API](https://developer.what3words.com/public-api/docs/#grid-section) supports the ability to obtain a section of the 3m x 3m what3words grid in GeoJSON format, making it very simple to display on a map. This tutorial will show you how to integrate the what3words grid with LeafletJS. We also have tutorials demonstrating its use with both [Mapbox](https://developer.what3words.com/tutorial/displaying-the-what3words-grid-on-a-mapbox-map) and [Google Maps](https://developer.what3words.com/tutorial/displaying-the-what3words-grid-on-a-google-map). LeafletJS is an open source JavaScript mapping engine. More information can be found at [https://leafletjs.com/reference-1.5.0.html.](https://leafletjs.com/reference-1.5.0.html.) [Grid Section Map Overlay (Leaflet)](https://codesandbox.io/s/grid-section-map-overlay-leaflet-zz0ik) (interactive example) ## 1. Get API key You will need a what3words API key to complete this tutorial. [Get an API Key](https://accounts.what3words.com/select-plan) or [sign in](https://accounts.what3words.com/). ## 2. Installation To load the JavaScript wrapper for the what3words API, use a `script` tag like the one in the following example. Replace `YOUR-API-KEY` with your what3words API key to get started. **Note:** We prefer to use a fixed version of the production version of your integrations. A specific version can also be specified within the script to ensure a predictable version of the component is loaded, for example`@5.0.0`. A log of versions can be found [here.](https://developer.what3words.com/tutorial/javascript-autosuggest-component#versioning) **JavaScript** ```javascript ``` The URL contained in the script tag is the location of a JavaScript file that loads everything you need for using the JavaScript wrapper for the what3words API. The `key` parameter contains your application’s API key. You will also need to load the LeafletJS API, for example: **JavaScript** ```javascript ``` ## 3. Map style Within the `head` tag, we need to set style properties for LeafletJS. In this example, we’ll set the map to display full screen. **JavaScript** ```javascript ``` ## 4. Map initialisation Within the `body` tag, we need to create a new div element to contain the map component, as well as initialise it using the LeafletJS API. **JavaScript** ```javascript
``` ## 5. Grid overlay The what3words grid can be displayed on top of a LeafletJS Map adding a [GeoJSON layer](https://leafletjs.com/examples/geojson/) to the map. Because only a segment of grid section can be requested, we need to obtain a new grid section each time the map is panned or zoomed. **JavaScript** ```javascript ``` ### Full example The example below takes the step by step guide and puts them into a complete, working example. **JavaScript** ```javascript Grid Section Map Overlay (Leaflet)
``` --- # Displaying the what3words grid on a Mapbox Map Adding a Mapbox Map to your website with the what3words grid Topics: JavaScript, Mapbox, Website Section: [Display Map](https://developer.what3words.com/docs/display-map.md) > [Display the what3words grid](https://developer.what3words.com/docs/display-map/display-the-what3words-grid.md) Source: https://developer.what3words.com/tutorial/displaying-the-what3words-grid-on-a-mapbox-map Updated: 2026-11-27 ### Step by step The [what3words API](https://developer.what3words.com/public-api/docs/#grid-section) supports the ability to obtain a section of the 3m x 3m what3words grid in GeoJSON format, making it very simple to display on a map. This tutorial will show you how to integrate the what3words grid with Mapbox. We also have tutorials demonstrating its use with both [Google Maps](https://developer.what3words.com/tutorial/displaying-the-what3words-grid-on-a-google-map) and [Leaflet](https://developer.what3words.com/tutorial/displaying-the-what3words-grid-on-a-leafletjs-map). You will also need to sign up for a Mapbox developer account and be able to view other Mapbox tutorials at [https://docs.mapbox.com/mapbox-gl-js/api/](https://docs.mapbox.com/mapbox-gl-js/api/) [Grid Section Map Overlay (Mapbox)](https://codesandbox.io/s/grid-section-map-overlay-mapbox-zpdx0) (interactive example) ## 1. Get API key You will need a what3words API key to complete this tutorial. [Get an API Key](https://accounts.what3words.com/select-plan) or [sign in](https://accounts.what3words.com/). ## 2. Installation To load the JavaScript wrapper for the what3words API, use a `script` tag like the one in the following example. Replace `YOUR-API-KEY` with your what3words API key to get started. **Note:** We prefer to use a fixed version of the production version of your integrations. A specific version can also be specified within the script to ensure a predictable version of the component is loaded, for example`@5.0.0`. A log of versions can be found [here.](https://developer.what3words.com/tutorial/javascript-autosuggest-component#versioning) **JavaScript** ```javascript ``` The URL contained in the `script` tag is the location of a JavaScript file that loads everything you need for using the JavaScript wrapper for the what3words API. The `key` parameter contains your application’s API key. You will also need to load the Mapbox API, for example: **JavaScript** ```javascript ``` ## 3. Map style Within the `head` tag, we need to set style properties for the Mapbox Map. In this example, we’ll set the map to display full screen. **JavaScript** ```javascript ``` ## 4. Map initialisation Within the `body` tag, we need to create a new `div` element to contain the map component, as well as initialise it using the Mapbox JavaScript API. **JavaScript** ```javascript
``` ## 5. Grid overlay The what3words grid can be displayed as a Mapbox layer by creating a GeoJSON data source, and [attaching it to a new layer](https://docs.mapbox.com/mapbox-gl-js/example/geojson-line/). Because only a segment of grid section can be requested, we need to obtain a new grid section each time the map is panned or zoomed. **JavaScript** ```javascript ``` ### Full example The example below takes the step by step guide and puts them into a complete, working example. **JavaScript** ```javascript Grid Section Map Overlay (Mapbox)
``` --- # Using the iOS Map Component Displaying the what3words grid and marker on Apple Maps' new or existing map applications. Topics: Swift, Mobile App Section: [Display Map](https://developer.what3words.com/docs/display-map.md) Source: https://developer.what3words.com/tutorial/using-the-ios-map-component Updated: 2026-11-27 ### Tutorial ### Introduction The easiest way to add what3words to your technology is to use one of our components. We have several components available for JavaScript, iOS, and Android which require minimal development to integrate. The what3words iOS Map Component provides a straightforward way to add what3words grid on top of your `MKMapView` or a full-featured map View Controller, displaying the what3words address and marker on the map for a selected  3 word address. This tutorial steps through how our iOS Map Component can be added to a new project that requires creating a map from scratch or to an existing map: - If you are creating a new map from scratch using our Map component then we recommend using our Map Component: W3WMapViewController; - If you want to add what3words to an existing map then we recommend using our Map Helper: W3WMapHelper; - If you are looking for a quick and dirty way to get the what3words functionality into your app we recommend using our Map View: W3WMapView. Follow the steps below to select your chosen way to integrate our what3words map component into your project.< GitHub repo: [https://github.com/what3words/w3w-swift-components](https://github.com/what3words/w3w-swift-components). ### Quickstart The iOS Map Component requires just a few lines of code to be added to an iOS application to create a map with what3words functionality. - Replace YOUR-API-KEY with your what3words API key. - It is compatible with applications that are built using iOS 9.0 or higher. - If you are upgrading from any version 1.x.x, see [this upgrade guide](https://github.com/what3words/w3w-swift-components/blob/master/Documentation/PreviousVersions/UpgradeFromV1.md). Here are listed some sample apps that can be used: - [Map Component Sample](https://github.com/what3words/w3w-swift-samples/tree/main/MapComponent); - [Map Helper Sample](https://github.com/what3words/w3w-swift-samples/tree/main/MapHelper); - [Map Viewer Sample](https://github.com/what3words/w3w-swift-samples/tree/main/MapView) ![ios\_map\_component\_final\_result](https://kpcwlqbjuaezxoatdmqy.supabase.co/storage/v1/object/public/devsite-media/wp/38d78ec51b6ae50999ddc8ed2d5b68252a120254aac18e20557e3adaa5015b74.w1600.webp) **Swift** ```swift class ViewController: W3WMapViewController { override func viewDidLoad() { super.viewDidLoad() let api = What3WordsV3(apiKey: "Enter your what3words API key") self.set(api) self.set(language: "en") let textField = W3WAutoSuggestTextField(api) self.attach(textField: textField) textField.onSuggestionSelected = { suggestion in self.removeAllMarkers() self.addMarker(at: suggestion, camera: .zoom) } self.onSquareSelected = { square in self.removeAllMarkers() self.addMarker(at: square, camera: .center) testField.set(display: square) } let button = W3WMapTypeButton() attach(view: button, position: .bottomRight) // if there is an error then add it as an alert onError = { error in self.showError(error: error) } } /// set here the showError() function func showError(error: Error) { DispatchQueue.main.async { let alert = UIAlertController(title: "Error", message: String(describing: error), preferredStyle: .alert) alert.addAction(UIAlertAction(title: "Dismiss", style: .cancel, handler: nil)) self.present(alert, animated: true) } } } ``` ### Step by Step ## 1. Get API key You will need a what3words API key to complete this tutorial. [Get an API Key](https://accounts.what3words.com/select-plan) or [sign in](https://accounts.what3words.com/). ## 2. Add the dependency The iOS Map Component depends on the [what3words swift wrapper](https://github.com/what3words/w3w-swift-wrapper), make sure you will add it as a Package Dependency. Follow these easy steps to add this swift package to your project: 1. From Xcode’s File menu choose `Swift Packages` then `Add Package Dependancy`. 2. The Choose Package Repository window appears. Add [https://github.com/what3words/w3w-swift-components.git](https://github.com/what3words/w3w-swift-components.git) in the search box, and click on `Next`. 3. If you are satisfied with the selected version branch choices, click Next again. 4. You should then be shown as a “Package Product” `W3WSwiftComponents`. Choose `Add Package`. Xcode should now automatically install `w3w-swift-components`, and `w3w-swift-wrapper`. Go to your `ViewController.swift` file and add the following libraries: **Swift** ```swift import W3WSwiftApi import W3WSwiftComponents ``` ## 3. New app using W3WMapViewController If you are starting a new project and you are creating a new app from scratch, we recommend using our W3WMapViewController which is a high-level component that has easy-to-use what3words functionality. Add the following class `W3WMapViewController` to the `ViewController` of your project. You will just have a Map view, no what3words functionality has been added yet at this point. **Swift** ```swift import UIKit import W3WSwiftApi import W3WSwiftComponents class ViewController: W3WMapViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } } ``` You will need to add your [what3words API key](https://what3words.com/select-plan) here to display the Map Component: **Swift** ```swift class ViewController: W3WMapViewController { override func viewDidLoad() { super.viewDidLoad() let api = What3WordsV3(apiKey: "Enter your what3words API key") } } ``` To refer to the map add the following line of code to your `viewDidLoad()` function below the `api` variable: **Swift** ```swift class ViewController: W3WMapViewController { override func viewDidLoad() { super.viewDidLoad() let api = What3WordsV3(apiKey: "Enter your what3words API key") // set the map view --> self = map self.set(api) } } ``` After adding this snippet run your application and you will display the Apple Maps with the what3words grid on top of it. ![grid\_on\_map](https://kpcwlqbjuaezxoatdmqy.supabase.co/storage/v1/object/public/devsite-media/wp/edc97cf3b373515b5c8c6a2aaf30299edb8ecc088a78fa78a69d38b493a12fd5.w1600.webp) ### Customise the Map Component The Map Component can be customised using some what3words properties. Here is shown an example where you can add a simple market to your Map with a specified what3words address. It will place an annotation on the map, if the map is zoomed in, it will appear as a square, and if zoomed out it shows as a what3words annotation icon. ![customise\_map\_component](https://kpcwlqbjuaezxoatdmqy.supabase.co/storage/v1/object/public/devsite-media/wp/ffd6fdbeb45453e3375d4ec1a77fbf8950ede443111d071bfc96caed365915c9.w1600.webp) **Swift** ```swift class ViewController: W3WMapViewController { override func viewDidLoad() { super.viewDidLoad() let api = What3WordsV3(apiKey: "Enter your what3words API key") self.set(api) // add Marker with a specified what3words address self.addMarker(at: "filled.count.soap") } } ``` You can set a language to get all the 3wa in the desired language (default english) by adding this line of code within the `viewDidLoad` function: **Swift** ```swift class ViewController: W3WMapViewController { override func viewDidLoad() { super.viewDidLoad() let api = What3WordsV3(apiKey: "Enter your what3words API key") self.set(api) // set language to get all the what3words self.set(language: "en") self.addMarker(at: "filled.count.soap") } } ``` You can make the map marker change color or their position on the map or add a list of specified what3words addresses. **Note:** the default colour of the marker is the brand’s red. ![multiple\_markers](https://kpcwlqbjuaezxoatdmqy.supabase.co/storage/v1/object/public/devsite-media/wp/f2b616408423ad57c020529890931eee2ac85ec75ce5357420e9b0f6dee173fa.w1600.webp) **Swift** ```swift class ViewController: W3WMapViewController { override func viewDidLoad() { super.viewDidLoad() let api = What3WordsV3(apiKey: "Enter your what3words API key") self.set(api) self.set(language: "en") // an example on how to add a blue marker on a valid 3 word address and move the map view to the center with multiple markers on the map self.addMarker(at:["filled.count.soap", "index.home.raft"], camera: .center, color: .blue) } } ``` You could also pass in a what3words suggestion to the `addMarker` property: ![suggestions\_marker](https://kpcwlqbjuaezxoatdmqy.supabase.co/storage/v1/object/public/devsite-media/wp/1a33405638cebe347e3e26300c649668a7ddfcb2ecca0aba64854be84b0e050b.w1600.webp) **Swift** ```swift class ViewController: W3WMapViewController { override func viewDidLoad() { super.viewDidLoad() let api = What3WordsV3(apiKey: "Enter your what3words API key") self.set(api) self.set(language: "en") // an example on how to add a what3words suggestions to the marker api.autosuggest(text: "filled.count.s") { suggestions, error in self.addMarker(at: suggestions) } } } ``` You could also restrict your what3words address suggestions to a desired country using `W3WOptions()` as shown here: ![suggestions\_marker\_with\_clipping](https://kpcwlqbjuaezxoatdmqy.supabase.co/storage/v1/object/public/devsite-media/wp/1ec427af3cbe06612cdda2c2dae64dc1e7644a393e833edfd7f48f2c328037ea.w1600.webp) **Swift** ```swift class ViewController: W3WMapViewController { override func viewDidLoad() { super.viewDidLoad() let api = What3WordsV3(apiKey: "Enter your what3words API key") self.set(api) self.set(language: "en") // an example on how to add a what3words suggestions to the marker clipped to a desired country let options = W3WOptions().clipToCountry("GB") api.autosuggest(text: "filled.count.s", options: options) { suggestions, error in self.addMarker(at: suggestions) } } } ``` ### Access the map view To access the Map View you can use an accessor variable called `w3wMapView` which is an `MKMapView`. ### Listening for events Now when you click on the map marker you can display the what3words address if you trigger the `onSquareSelected` event. **Note:** Only one square can be selected at the same time, just like our core apps. ![selected\_square](https://kpcwlqbjuaezxoatdmqy.supabase.co/storage/v1/object/public/devsite-media/wp/87c632b054d8bf7867936fd7d6991d292500df1de041fa831aa11ae5306a9bf2.w1600.webp) **Swift** ```swift class ViewController: W3WMapViewController { override func viewDidLoad() { super.viewDidLoad() let api = What3WordsV3(apiKey: "Enter your what3words API key") self.set(api) self.set(language: "en") // an example when a point is touched on the map and highlights its 3x3m what3words square, self.onSquareSelected = { square in // this clears previous what3words annotations and selected squares self.removeAllMarkers() self.addMarker(at: square, camera: .center) } } } ``` ### Use AutoSuggest Component in the Search field If you want to add the AutoSuggest Component to the search box on top of the Map Component, you need to update your `viewDidLoad()` function to both have the what3words components, the `W3WAutoSuggestTextField` (for the AutoSuggest Component) and `W3WMapViewController` (for the Map Component). ![autosuggest\_text\_field](https://kpcwlqbjuaezxoatdmqy.supabase.co/storage/v1/object/public/devsite-media/wp/eb5f9a3a9708cd80654056faa00e877a02cd83c1870cb69791f4c5faf7bb5b46.w1600.webp) **Swift** ```swift class ViewController: W3WMapViewController { override func viewDidLoad() { super.viewDidLoad() let api = What3WordsV3(apiKey: "Enter your what3words API key") self.set(api) self.set(language: "en") // Add an AutoSuggest Component text field, and attach it to the view let textField = W3WAutoSuggestTextField(api) self.attach(textField: textField) // when an AutoSuggest suggestion is selected from the text field, show it on the map and clear previous selections textField.onSuggestionSelected = { suggestion in self.removeAllMarkers() self.addMarker(at: suggestion, camera: .zoom) } self.onSquareSelected = { square in self.removeAllMarkers() self.addMarker(at: square, camera: .center) // this add the what3words address to the text field textField.set(display: square) } } } ``` If you want to add the voice functionality to the AutoSuggest Text Field Component you need to make sure to add the following line of code right after you declare the `textField` variable **Swift** ```swift let textField = W3WAutoSuggestTextField(api) // Add an AutoSuggest text field component with the voice option, and attach it to the view (voice functionality requires API key permissions, contact what3words to enable this - https://accounts.what3words.com/overview) textField.set(voice: true) attach(textField: textField) ``` ### Customise map type If you are familiar with `MKMapView` you can set up different map types `MKMapType`, for example: - `.standard` if you want to display street map `mapView.mapType = .standard` - `.satellite` if you want to displays satellite imagery `mapView.mapType = .satellite` Here is what your application should look like: ![ios\_map\_component\_final\_result](https://kpcwlqbjuaezxoatdmqy.supabase.co/storage/v1/object/public/devsite-media/wp/38d78ec51b6ae50999ddc8ed2d5b68252a120254aac18e20557e3adaa5015b74.w1600.webp) ## 4. Existing app using W3WMapHelper If you already have an application with a map we recommend using our Map Helper, `W3WMapHelper` in your app. It provides convenience functions to add to your `MKMapViewDelegate` functions for what3words grid and pin annotations to be displayed on your map. An iOS UIKit example project can be out [here](https://github.com/what3words/w3w-swift-components/blob/master/Examples/MapHelper/MapHelper.xcodeproj). This example shows where you would place the calls, and how to instantiate the `W3WMapHelper`. **Note:** the `W3WMapHelper` is conforms to the `W3WMapViewProtol`. A function reference is described below in the Map Component Functions. **Swift** ```swift let api = What3WordsV3(apiKey: "YourApiKey") let mapHelper = W3WMapHelper(api, map: yourMKMapView) ``` ## 5. Existing app using W3WMapView If you are keen on using our Map View, `W3WMapView`, as a quick and dirty way to quickly get what3words functionality into your app, simply replace your `MKMapView` with `W3WMapView`, and your app should behave the same as before except it will draw what3words grid lines and have some new functions available, like `addMarker(at: "filled.count.soap")`. The `W3WMapView` is derived from `MKMapView` but Apple does not recommend deriving new objects from `MKMapView` presumably, because its interface could change in the future. A better approach to inserting our map component into your existing map would be to use our `W3WMapHelper` which is designed to fit nicely into your `MKMapViewDelegate` conforming class, presumably a `UIViewController`. An iOS UIKit example project can be out [here](https://github.com/what3words/w3w-swift-samples/tree/main/MapView/MapView.xcodeproj). **Note:** the `W3WMapHelper` is conforms to the `W3WMapViewProtol`. A function reference is described below in the Map Component Functions. **Swift** ```swift let api = What3WordsV3(apiKey: "YourApiKey") let mapview = W3WMapView(api) ``` ## 6. Configuring for use with API server If you run our Enterprise Suite API Server yourself, you may specify the URL to your own server by adding this line of code to the Map Component: **Swift** ```swift val api = What3WordsV3(apiKey: "YOUR_API_KEY_HERE", apiUrl: "https://api.yourserver.com") ``` ## 7. Map Component Functions | Method Name | Description | Example | | --- | --- | --- | | addMarker(at: \_, camera: W3WCenterAndZoom, color: UIColor?, style: W3WMarkerStyle) | This parameter will place an annotation on the map, if the map is zoomed in, it will appear as a square, and if zoomed out it shows as a what3words annotation icon. addMarker(at:camera:color) takes one required parameter and two optional ones. The first is the location, this can be a what3words address as: - words: String, - suggestion: W3WSuggestion, - squares: W3WSquare, - coordinates: CLLocatioinCorrdinate2D, - or it can be an array of any of those. Note: if you pass in a String, or W3WSuggestion, a call to convertToCoordinates will be made automatically to get the coordinates, and this will count towards your account quota. The second and optional parameter is called camera and it indicates how to move the map view. The choices are: - .zoom - zooms the map into the location right around the square - .center - adjusts the map's center so that the location is in the center, but does not zoom in - .none - this leaves the mapView showing the same area it was showing before the call The third and optional parameter is color which takes a UIColor color for the annotation. The default colour is the what3words brand's red. | map.addMarker(at:square, camera: .zoom) map.addMarker(at:"filled.count.soap", style: .pin) map.addMarker(at:\["filled.count.soap", "index.home.raft"\], camera: .center) map.addMarker(at:\["filled.count.soap", "index.home.raft"\], color: .blue, camera: .center) | | getMapAnnotationView(annotation: MKAnnotation) -> MKAnnotationView? | If the annotation is a what3words one, this parameter gets a renderer, otherwise, it returns nil. If you are using W3WMapHelper then this is typically called in your MKMapViewDelegate's call: mapView(\_, viewFor: MKAnnotation) | getMapAnnotationView(annotation: annotation) | | mapRenderer(overlay: MKOverlay) -> MKOverlayRenderer?addMarkerAtWords | This parameter gets a renderer for the what3words grid if it is given a W3WMapGridLines or W3WMapSquareLines overlay, otherwise, it returns nil. If you are using W3WMapHelper then this is typically called in your MKMapViewDelegate's call: mapView(\_, rendererFor: MKOverlay) | mapRenderer(overlay: overlay) | | removeAllMarkers() | This parameter will hide an annotation that was previously placed on the map. It takes one parameter and like addMarker(), it can be a what3words address as: - words: String, - suggestion: W3WSuggestion, - coordinates: CLLocatioinCorrdinate2D, - or it can be an array of any of those. | map.removeAllMarkers() | | removeMarker(at:) | This method allow you to get all added markers from the map. | map.removeMarker(at: square) map.removeMarker(at: "filled.count.soap") map.removeMarker(at: \["filled.count.soap", "index.home.raft"\]) | | set(language: String) | This parameter will set the default language for all the calls that the map makes to the API (or SDK if you use that instead). | map.set(language: "fr") // set default language to French | | set(zoomInPointsPerSquare: CGFloat) | This parameter will set how near the addMarker(at: "filled.count.soap", camera: .zoom) calls will zoom. zoomInPointsPerSquare is the size of squares in points when .zoom is used in an addMarker() call. (points being 1x, 2x, 3x a pixel depending on which device you are using and if it has a "retina" display. | set(zoomInPointsPerSquare: x.x) | | updateMap() | This parameter updates the map view with annotations and lines. If you are using W3WMapHelper then this is typically called in your MKMapViewDelegate's calls: mapViewDidChangeVisibleRegion() mapView(\_, regionWillChangeAnimated), and mapView(\_, regionDidChangeAnimated). | updateMap() | ## 8. Events | Event | Description | Example | | --- | --- | --- | | onMarkerSelected | This parameter is called when the user taps a square that has a marker added to it. | self.onMarkerSelected = { square in self.addMarker(at: square, camera: .center)} | | onSquareSelected | This parameter is called when the user taps a square on a map. | self.onSquareSelected = { square in self.addMarker(at: square, camera: .center)} | | onError | This parameter returns the error enum for any error that occurs. | onError = { error in self.showError(error: error) } | ### Listening for events Using an event listener, it is possible to fire other functionality in an app when something changes in the Map Component. For example, when you click on the map marker you can display the what3words address if you trigger the `onSquareSelected` event. **Note:** Only one square can be selected at the same time, just like our core apps. **Swift** ```swift class ViewController: W3WMapViewController { override func viewDidLoad() { super.viewDidLoad() let api = What3WordsV3(apiKey: "Enter your what3words API key") self.set(api) self.set(language: "en") // an example when a point is touched on the map and highlights its 3x3m what3words square, self.onSquareSelected = { square in // this clears previous what3words annotations and selected squares self.removeAllMarkers() self.addMarker(at: square, camera: .center) } } } ``` ## 9. Troubleshooting If you encounter errors or issues related to convert-to-coordinate, convert-to-3wa and grid-section requests while using the Free plan, please check the network panel for the following error message `Error 402 payment required` and its response, indicating the need to upgrade to a higher plan: **JSON** ```json { "error": { "code": "QuotaExceeded", "message": "Quota exceeded or API plan does not have access to this feature. Please change your plan at https://accounts.what3words.com/select-plan, or contact support@what3words.com" } } ``` For more information, visit our [API plans page](https://accounts.what3words.com/select-plan). If you need further assistance, contact [support@what3words.com](mailto:support@what3words.com). ### Issue *How to make the textfield suggest actual addresses (not w3w)?* ### Solution Currently, it’s not possible with the iOS AutoSuggest Component. There is, however, an example of this in [w3w-swift-wrapper](https://github.com/what3words/w3w-swift-wrapper) called [AutosuggestPlusYourData](https://github.com/what3words/w3w-swift-samples/tree/main/AutosuggestPlusYourData). You can use this as a guide or even take some of the code from it for your use. --- # Using the Web Map Component Displaying the what3words grid and marker on Google Maps. Topics: Angular, JavaScript, React, Vue, Website Section: [Display Map](https://developer.what3words.com/docs/display-map.md) Source: https://developer.what3words.com/tutorial/using-the-web-map-component Updated: 2026-11-27 ### Tutorial ### Introduction The easiest way to add what3words to your technology is to use one of our components. We have several components available for JavaScript, iOS, and Android which require minimal development to integrate. They can also be used in Angular, React, or Vue projects as framework-native components. Find out how else you can utilise the what3words API using JavaScript by taking a look at the functions in the what3words [JavaScript API Wrapper](https://developer.what3words.com/tutorial/javascript). The web map component declares a custom DOM element that allows for a quick and simple way of adding the what3words grid on top of Google Maps, displaying the what3words address and marker on the map for a selected three word address. You can optionally integrate the AutoSuggest Component with the map too and it will enable searching of 3 word addresses or traditional addresses and traverses the map to the selected three word address. The component by default uses the what3words API or can be configured to use a privately hosted instance of the what3words API. This tutorial steps through how our JavaScript Map Component can be added to a website either for static pages via our CDN or using NPM as part of your project dependencies. Follow the steps below to select your chosen technology to find out how you can add the what3words map component to your project. ### Quickstart The Web Map Component requires just a few lines of code to be added to a site to create a map with what3words functionality. Replace `YOUR-API-KEY` with your what3words API key and the `YOUR-GOOGLE-API-KEY` with your Google Maps API key. **HTML** ```html
``` **React** ```jsx import { What3wordsAutosuggest, What3wordsMap } from "@what3words/react-components"; const API_KEY = "YOUR-API-KEY"; const MAP_API_KEY = "YOUR-GOOGLE-API-KEY"; export default function Map() { return (
); } ``` **Vue** ```vue ``` **Angular** ```typescript import { NgModule } from "@angular/core"; import { Component } from "@angular/core"; import { ComponentsModule } from "@what3words/angular-components"; @Component({ selector: "app-component-map", template: `
`, styles: [` html, body { margin: 0px; height: 100%; } #map-container { width: 100vw; height: 100vh; } #search-container { margin: 10px 0 0 10px; } #search-input { width: 300px; } #current-location-container { margin: 0 10px 10px 0; } `] }) export class W3WMapComponent { } @NgModule({ imports: [ComponentsModule], declarations: [W3WMapComponent], exports: [W3WMapComponent], bootstrap: [W3WMapComponent] }) export class W3WMapModule { } ``` [Web Map Component](https://codesandbox.io/s/web-map-component-static-sample-nimy60) (interactive example) ### Step by Step ## 1. Get API key You will need a what3words API key to complete this tutorial. [Get an API Key](https://accounts.what3words.com/select-plan) or [sign in](https://accounts.what3words.com/). ## 2. Get Google API key You also will need to get a [Google API key](https://developers.google.com/maps/documentation/places/web-service/get-api-key#console) for your chosen map provider (only Google is currently supported). **Note:** In [console.cloud.google.com](http://console.cloud.google.com/) you should select: `API and services` > `Enabled APIs and services` Search for `places API` and then select and enable it. ## 3. Add Map Component The component can be added to static HTML pages by including the `what3words.js` script on each page of your site that you would like to use the component on. A notable limitation imposed by Google Maps restricts the number of maps that can be rendered on any single page (details are provided in the `Troubleshooting` section). You will need to replace `` with your what3words API key. This will attach the what3words API to the `window` accessible via `window.what3words`. This parameter is only required if you need the latter functionality. Alternatively, if you are using a package manager (e.g. `npm`) within your site you can consume one of our packages for your framework. **HTML** ```html ``` **JavaScript** ```javascript npm install @what3words/javascript-components@5.0.0 ``` **React** ```jsx npm install @what3words/react-components@5.0.0 ``` **Vue** ```vue npm install @what3words/vue-components@5.0.0 ``` **Angular** ```typescript $ npm install @what3words/angular-components@5.0.0 ``` ### Add Current Location Functionality (Optional) To enable your customers to choose their current location and discover their three word address, you will need to add a `current-location-control` slot container with a child button as a sibling to the `search-control` slot. This can be styled using CSS with its position on the map canvas controlled by the `current_location_control_position` What3Words Map Component property. A simple implementation is shown below: **HTML** ```html ...
... ``` **React** ```jsx ...
... ``` **Vue** ```vue ...
... ``` **Angular** ```typescript ...
... ``` ### Insert Map Component Then we will need to wrap the map container and the search box within the what3words Map Component as shown here to display the what3words grid and marker on Google Maps. Notice you will need to add your what3words API key to the `api_key` parameter and your Google Maps API key to `map_api_key` parameter. **Note:** You will also need to add an `import` line to our package if you are using npm. **HTML** ```html ``` **React** ```jsx import { What3wordsMap } from "@what3words/react-components"; const API_KEY = "YOUR-API-KEY"; const MAP_API_KEY = "YOUR-GOOGLE-API-KEY" export default function Map() { return ( ); } ``` **Vue** ```vue ``` **Angular** ```typescript import { NgModule } from "@angular/core"; import { Component } from "@angular/core"; import { ComponentsModule } from "@what3words/angular-components"; @Component({ selector: "app-component-map", template: ` `, styles: [` ... `] }) export class W3WMapComponent { } @NgModule({ imports: [ComponentsModule], declarations: [W3WMapComponent], exports: [W3WMapComponent], bootstrap: [W3WMapComponent] }) export class W3WMapModule { } ``` ### Define a map container Add HTML and CSS to create a page with a `#map` element. The `#map` is the element that displays the map and its CSS resets any browser settings, so it can consume the full width and height of the browser. Note that we must specifically declare those percentages for <**body**\> and <**html**\> as well. For the map to display on a web page, we must reserve a spot for it. Commonly, we do this by creating a named <**div**\> element and obtaining a reference to this element in the browser’s document object model (DOM). **HTML** ```html
``` **React** ```jsx import { What3wordsMap } from "@what3words/react-components"; const API_KEY = "YOUR-API-KEY"; const MAP_API_KEY = "YOUR-GOOGLE-API-KEY" export default function Map() { return (
); } ``` **Vue** ```vue ``` **Angular** ```typescript ... template: `
`, ... ``` **CSS** ```css ``` ### Insert Search field You could insert a seach box by simply adding a `search-control slot` within the Map Component. In the `search-control slot` you can specify your customised search box. **HTML** ```html
// Enter here your customised Search box
``` **React** ```jsx import { What3wordsMap } from "@what3words/react-components"; const API_KEY = "YOUR-API-KEY"; const MAP_API_KEY = "YOUR-GOOGLE-API-KEY" export default function Map() { return (
// Enter here your customised Search box
); } ``` **Vue** ```vue ``` **Angular** ```typescript ... template: `
// Enter here your customised Search box
`, ... ``` ### Use AutoSuggest Component in the Search field (Optional) You could also provide a type-ahead search box that includes the what3words Web AutoSuggest Component and the common address from Google Places, you will need to add the following code on your body below the `div` element that is used as a map container. **Note:** This is completly optional. You will also need to add an `import` line to our AutoSuggest Component package if you are using `npm`. **HTML** ```html
``` **React** ```jsx import { What3wordsAutosuggest, What3wordsMap } from "@what3words/react-components"; const API_KEY = "YOUR-API-KEY"; const MAP_API_KEY = "YOUR-GOOGLE-API-KEY" export default function Map() { return (
); } ``` **Vue** ```vue ``` **Angular** ```typescript ... template: `
`, ... ``` ### Customise the Map Component The Map Component can be customised using common Google Maps options and other what3words properties. Here is shown an example of how to add these options and properties together. **HTML** ```html ... ``` **React** ```jsx ... ``` **Vue** ```vue ... ``` **Angular** ```typescript ... template: ` ... ` ... ``` ### Configuring for use with API server If you run our Enterprise Suite API Server yourself, you may specify the URL to your own server by adding the `base_url` parameter to the Map Component. **HTML** ```html ... ``` **React** ```jsx ... ``` **Vue** ```vue ... ``` **Angular** ```typescript ... ``` ### Styling Map Component By default, the Web Map Component will load with the what3words predefined map marker icon. You can choose your own icon by adding their URL path to the `marker_icon` attribute. **HTML** ```html ... ``` **React** ```jsx ... ``` **Vue** ```vue ... ``` **Angular** ```typescript ... ``` ### Select Map Provider Our Map Component could support different map service providers, such as Google Maps, Mapbox, Apple Maps, and many more, by adding the property `provider` to the Map Component. Currently, the only map service provider accepted is Google Maps `provider = "google"` but in the future will be extended to support `mapbox` (for MapBox), `apple` (for Apple Maps) and other map providers. **HTML** ```html ... ``` **React** ```jsx ... ``` **Vue** ```vue ... ``` **Angular** ```typescript ... ``` ### Add Strict mode You can now add `strict=false` or just `strict` if you want it to be true (which is the default) to the AutoSuggest Component which allows for non-3wa-like strings to be accepted and the component will not remove the value. It will emit the `value_invalid` event as it normally does, but the value is not removed and can be used to trigger another integration, such as Google Places API, which the map component does. This way you can now use the autosuggest component with an existing field rather than having to have a dedicated field on your form. ### Customise Suggestions (Optional) If you are using our AutoSuggest Component in your Search box, with the new alpha build you can also push your own suggestions to the AutoSuggest Component using the `option` attribute or programmatically updating this with JavaScript as is shown in the example below. This is currently available through the React and Vue wrappers. **React** ```jsx import { What3wordsAutosuggest } from "@what3words/react-components"; import { createRef, useEffect } from "react"; import "./styles.css"; export default function App() { const ref = createRef(); useEffect(() => { ref.current.addEventListener("value_invalid", () => { const options = [ { value: "Street A", id: "street-a", description: "Some village", distance: { value: 10, units: "km" } }, { value: "Street B", id: "street-b", description: "Some town", distance: { value: 30, units: "km" } }, { value: "Street C", id: "street-c", description: "Some city", distance: { value: 90, units: "metres" } } ]; ref.current.options = options; }); return () => ref.current.removeEventListener("value_invalid", () => { console.log("here"); }); }, [ref]); return ( ); } ``` ## 4. Attributes ### Component script parameters | Parameter | Type | Description | | --- | --- | --- | | key | String | An API key is required for the component to function correctly. Example: key=Your-API-Key | | baseUrl | String | The component can be used with an Enterprise Suite API Server instance by using baseUrl. Example: baseUrl=https://example.com/v3 | | callback | String | Allows for a callback to be fired once the component has loaded. This should be the function name to be fired. Example: callback=initMap | | headers | String | Enterprise API Server only - Allows for custom headers to be passed through in requests. | ### Component Attributes | Parameter | Type | Description | | --- | --- | --- | | api\_key | String | Your what3words API Key can be specified as an attribute to the component. Example: api\_key="Your-API-Key" | | api\_version | String | You can specify the what3words API version as an attribute to the component. Example: api\_version=”v1” | | base\_url | String | The component can be used with an Enterprise Suite API Server instance by using base\_url. Example: base\_url =https://example.com/v3 | | current\_location | Boolean | Enables/disables the current location. | | current\_location\_control\_position | Number | Position id. Used to specify the position of the current location control on the map. | | disable\_default\_ui | Boolean | Enables/disables all default UI buttons. May be overridden individually. Does not disable the keyboard controls or the gesture controls. | | fullscreen\_control | Boolean | The enabled/disabled state of the Fullscreen control. | | fullscreen\_control\_position | Number | Position Id. Used to specify the position of the control on the map. The default position is RIGHT\_TOP | | headers | String | Enterprise API Server only - Allows for custom headers to be passed through in requests. | | language | String | See https://developers.google.com/maps/faq#languagesupport Allows you to add a preferred suggestion fallback language for google maps. Example: language="EN" | | lat | Number | It specifies the latitude of an initial position on the map. Example: lat=-34.397. | | libraries | ("drawing" \| "geometry" \| "localContext" \| "places" \| "visualization") | It loads additional libraries by specifying a libraries parameter in the request, and supplying the name of the library or libraries. You can specify multiple libraries as a comma-separated list. See the full list here: https://developers.google.com/maps/documentation/javascript/libraries. | | lng | Number | It specifies the longitude of an initial position on the map. Example: lng=150.644 | | map\_api\_key | String | A Google Maps API key is required for the component to function correctly. | | map\_type\_control | Boolean | The initial enabled/disabled state of the Map type control. | | map\_type\_control\_position | Number | Position id. Used to specify the position of the map type control on the map. Default TOP\_RIGHT. | | map\_type\_id | "hybrid" \| "roadmap" \| "satellite" \| "terrain" | IDs of map types to show in the control. | | marker\_icon | String | You can use the default marker icon or use your own one \[MARKER\_SRC\]. Example: marker\_icon="logo\_sample.jpg". | | provider | String | Map Service provider. Currently it accepts only "google". In the future will be extended to support "mapbox", "apple" and other map service providers. | | region | String | A region code of the user's region. The region code accepts a ccTLD ("top-level domain") two-character value. Most ccTLD codes are identical to ISO 3166-1 codes, with some notable exceptions. For example, the United Kingdom's ccTLD is "uk" (.co.uk) while its ISO 3166-1 code is "gb" (technically for the entity of "The United Kingdom of Great Britain and Northern Ireland"). | | rotate\_control | Boolean | The enabled/disabled state of the Rotate control. | | rotate\_control\_position | Number | Position id. Used to specify the position of the rotate control on the map. The default position is TOP\_LEFT. | | scale\_control | Boolean | The initial enabled/disabled state of the Scale control. | | search\_control\_position | Number | Position id. Used to specify the position of the search control on the map. The default position is TOP\_LEFT. | | selected\_zoom | Number | The initial what3words Grid zoom level. | | street\_view\_control | Boolean | The initial enabled/disabled state of the Street View Pegman control. This control is part of the default UI, and should be set to false when displaying a map type on which the Street View road overlay should not appear (e.g. a non-Earth map type). | | street\_view\_control\_position | Number | Position id. Used to specify the position of the street view control on the map. The default position is embedded within the navigation (zoom and pan) controls. If this position is empty or the same as that specified in the zoom\_control\_position, the Street View control will be displayed as part of the navigation controls. Otherwise, it will be displayed separately. | | tilt | Number | For vector maps, sets the angle of incidence of the map. The allowed values are restricted depending on the zoom level of the map. For raster maps, controls the automatic switching behavior for the angle of incidence of the map. The only allowed values are 0 and 45. | | version | String | Google Maps JavaScript API version loaded by the browser. See https://developers.google.com/maps/documentation/javascript/versions. | | watch\_location | Boolean | It watches your location and the event listener will be triggered every time their location changes. | | words | String | Iniital what3words address to be searched and displayed on the map. | | zoom | Number | The initial Map zoom level. Valid zoom values are numbers from zero up to the supported maximum zoom level. Larger zoom values correspond to a higher resolution. | | zoom\_control | Boolean | The enabled/disabled state of the Zoom control. | | zoom\_control\_position | Number | Position id. Used to specify the position of the zoom control on the map. The default position is TOP\_LEFT. More on the ControlPosition constants on Google Maps:https://developers.google.com/maps/documentation/javascript/reference/control#ControlPosition. | ## 5. Events | Event | Description | | --- | --- | | coordinates\_changed | Fires when coordinates change when a new valid 3 word address is selected. Returns the coordinates of the selected square on the map. | | selected\_square | Fires when a square on the what3words grid has been selected. Returns all details of that selected square. | ### Listening for events Using an event listener, it is possible to fire other functionality in a site when something changes in the Map Component. For example, it is possible to listen for when a square on the grid map has been selected by the users or to listen for when new coordinates have been returned and pan/zoom a map to the location. **JavaScript** ```javascript ``` ## 6. Methods | Method Name | Results | | --- | --- | | clearGrid | clearGrid(); Parameters: None. Return Value: None. Reset the polilynes of the grid on the map. | | getBounds | getBounds(); Parameters: None. Return Value: LatLngBounds\|undefined. Returns the lat/lng bounds of the current viewport \[south: number; west: number; north: number; east: number;\]. If the map is not yet initialized or center and zoom have not been set then the result is undefined. | | getGrid | getGrid(); Parameters: None. Return Value: google.maps.Polyline\[\]. Returns the polylines of the grid on the map. | | getLat | getLat(); Parameters: None. Return Value: number\|undefined. Returns the latitude of an initial position on the map. If the latitude has not been set then the result is undefined. | | getLng | getLng(); Parameters: None. Return Value: number\|undefined. Returns the longitude of an initial position on the map. If the longitude has not been set then the result is undefined. | | getMapTypeId | getMapTypeId(); Parameters: None. Return Value: MapTypeId\|string\|undefined. Returns the MapTypeId of the map. | | getZoom | getZoom(); Parameters: None. Return Value: number\|undefined. Returns the zoom of the map. If the zoom has not been set then the result is undefined. | | panTo | panTo(coordinates); Parameters: coordinates: LatLng\|LatLngLiteral. The new center latitude/longitude of the map. Return Value: None. Changes the center of the map to the given coordinates. If the change is less than both the width and height of the map, the transition will be smoothly animated. | | setApiKey | setApiKey(key); Parameters: key: string. Return Value: None. | | setApiVersion | setApiVersion(api\_version); Parameters: api\_version: ApiVersion. Return Value: None. | | setBaseUrl | setBaseUrl(host); Parameters: host: string. Return Value: None | | setGrid | setGrid(grid); Parameters: grid: any\[\]. Return Value: None. | | setHeaders | setHeaders(value); Parameters: value: string. Enterprise API Server only - Allows for custom headers to be passed through in requests. Return Value: None. | | setLat | setLat(lat); Parameters: lat: number. It specifies the latitude of an initial position on the map. Return Value: None. | | setLng | setLng(lng); Parameters: lng: number. It specifies the longitude of an initial position on the map. Return Value: None. | | setMapTypeId | setMapTypeId(mapTypeId); Parameters: mapTypeId: MapTypeId\|string. Return Value: None. | | setOptions | setOptions(options); Parameters: options: MapOptions optional. Return Value: None. | | setWords | setWords(words); Parameters: words: string. Initial what3words address to be searched and displayed on the map. Return Value: None. Sets the initial what3words address on the map. | | setZoom | setZoom(zoom); Parameters: zoom: number. Larger zoom values correspond to a higher resolution. Return Value: None. Sets the zoom of the map. | ## 7. Full Example The example below takes the concepts described earlier and demonstrates how our JavaScript Map Component can be added to a website as an HTML static page via our CDN. [Map Component in an HTML Static Page](https://codesandbox.io/s/web-map-component-static-sample-nimy60) (interactive example) ## 8. Full Example in React The example below takes the concepts described earlier and demonstrates how our JavaScript Map Component can be added to a website using NPM as part of your project dependencies and React as a framework. [Map Component in React](https://codesandbox.io/s/web-map-component-in-react-r5k2s3) (interactive example) ## 9. Full Example in Vue The example below takes the concepts described earlier and demonstrates how our JavaScript Map Component can be added to a website using NPM as part of your project dependencies and Vue as a framework. [Map Component in Vue](https://codesandbox.io/s/web-map-component-in-vue-vgeecl) (interactive example) ## 10. Full Example in Angular The example below takes the concepts described earlier and demonstrates how our JavaScript Map Component can be added to a website using NPM as part of your project dependencies and Angular as a framework. [Map Component in Angular](https://codesandbox.io/s/web-map-component-in-angular-3e79gn) (interactive example) ## 11. Full Example in Angular with Routers The example below takes the concepts described earlier and demonstrates how our JavaScript Map Component can be added to a website using NPM as part of your project dependencies and Angular as a framework. If you are looking to build Single Page Applications with multiple views and allow navigation between these views you should use this code snippet to add the Angular Router. [Map Component in Angular with Router](https://codesandbox.io/s/web-map-component-with-router-in-angular-1424qm) (interactive example) ## 12. Troubleshooting If you encounter errors or issues related to convert-to-coordinate, convert-to-3wa and grid-section requests while using the Free plan, please check the network panel for the following error message `Error 402 payment required` and its response, indicating the need to upgrade to a higher plan: **JSON** ```json { "error": { "code": "QuotaExceeded", "message": "Quota exceeded or API plan does not have access to this feature. Please change your plan at https://accounts.what3words.com/select-plan, or contact support@what3words.com" } } ``` For more information, visit our [API plans page](https://accounts.what3words.com/select-plan). If you need further assistance, contact [support@what3words.com](mailto:support@what3words.com). ![google-maps-error](https://kpcwlqbjuaezxoatdmqy.supabase.co/storage/v1/object/public/devsite-media/wp/739e8708c7439d4bee0599f23ecdca0497ad4a031b004ee2e34ebfb4e1d5f57f.png) ## “For Development Purposes Only” on Google Maps ### Issue If you see a “For development purposes only” text over your Google Maps and it’s not loading correctly, there’s an issue with your Google Maps API key. This typically occurs because [Google Cloud Billing](https://console.cloud.google.com/billing) is not enabled, or a Google Maps API key has not been generated for your organization. ### Solution **1\. Enable Google Cloud Billing:** - Go to your [Google Cloud Billing](https://console.cloud.google.com/billing) settings and ensure billing is enabled. - Select your current project at the top left if necessary. Google requires billing to be enabled if your free trial has ended or if you’ve exceeded the free monthly tier. **2\. Generate a Google Maps API Key:** - Follow the instructions in the guide:  [How to add a Google Maps API key to your store locator](https://help.storerocket.io/en/articles/2126787-how-to-add-a-google-maps-api-key-to-your-storerocket-account). For further assistance, contact Google Cloud support. ![web-map-issue-loader](https://kpcwlqbjuaezxoatdmqy.supabase.co/storage/v1/object/public/devsite-media/wp/430b8376ca698ddd1c8bd7b94b9b993d6f3f4b749f974a6cdc309488089834b6.png) ## Google Maps Loader Error ### Issue If you encounter the following error in your console raised by the Google Maps loader package `js-api-loader`, it indicates an issue with creating multiple map instances. This error can occur due to: - Multiple re-renders with missing/different props passed to the Map component. - Attempting to load multiple maps on the same page with different properties. ### Solution This is a known issue that we aim to resolve in future releases. In the meantime, if you need multiple map instances on a single page, ensure you maintain the following properties for every what3words Map component: - `map_api_key` - `language` - `libraries` - `region` While this workaround is not officially supported, it may help mitigate the issue. For further assistance, please get in touch with [support@what3words.com](mailto:support@what3words.com). ## Vite Compatibility Issue Our current components do not yet work with Vite due to a known issue with Stencil. A potential fix is expected in a future version upgrade, which we are currently working on. It may take some time before this fix is available and tested. For now, we advise against using Vite. For more details, refer to the [GitHub issue](https://github.com/ionic-team/stencil/issues/2827). #### AI coding agents (like **Replit**, **Lovable and** **Cursor**) should follow the steps below when building with what3words. **Markdown** ~~~~markdown what3words — Map Component (Agent Guide, CDN‑only) Goal: Minimal POC that shows a full‑viewport map and a what3words search. Picking a suggestion recentres the map to that 3‑word address. No bundler edits, no extra packages. Rules (for humans & agents): - Use CDN web‑components only. Do not install `@what3words/*` or edit Vite config. - Secrets: `VITE_W3W_API_KEY` (what3words) and `VITE_GOOGLE_MAP_API_KEY` (Google Maps). - Wire selection → map: listen for `"selected_suggestion"` and set the map’s `words` property. No manual API calls required. --- ## 1) Set the API keys - `VITE_W3W_API_KEY` → what3words key - `VITE_GOOGLE_MAP_API_KEY` → Google Maps JavaScript API key --- ## 2) Load the components (no npm) Open `client/index.html` and paste these two lines just before ``: ```html ``` This defines `` and `` at runtime — no Vite changes needed. --- ## 3) Minimal `client/src/App.tsx` ```tsx import { useEffect, useRef } from "react"; // allow the custom elements without extra .d.ts files declare global { namespace JSX { interface IntrinsicElements { "what3words-map": any; "what3words-autosuggest": any; } } } const W3W_KEY = import.meta.env.VITE_W3W_API_KEY as string | undefined; const GMAPS_KEY = import.meta.env.VITE_GOOGLE_MAP_API_KEY as string | undefined; export default function App() { const mapRef = useRef(null); const autoRef = useRef(null); if (!W3W_KEY || !GMAPS_KEY) { return (

Set VITE_W3W_API_KEY and VITE_GOOGLE_MAP_API_KEY then rerun.

); } useEffect(() => { const el = autoRef.current; const onSelect = (e: any) => { const words = e.detail?.suggestion?.words as string; if (words && mapRef.current) mapRef.current.words = words; // recentre map }; el?.addEventListener("selected_suggestion", onSelect); return () => el?.removeEventListener("selected_suggestion", onSelect); }, []); return ( {/* map canvas fills the visible viewport */}
{/* centred search bar overlay */}
); } ``` ~~~~ --- # Displaying the what3words grid on a Bing Maps Adding a Bing Maps to your website with the what3words grid. Topics: JavaScript, Website Section: [Display Map](https://developer.what3words.com/docs/display-map.md) > [Other Map Types](https://developer.what3words.com/docs/display-map/other-map-types.md) Source: https://developer.what3words.com/tutorial/displaying-the-what3words-grid-on-a-bing-maps Updated: 2026-11-27 ### Step by step The [what3words API](https://docs.what3words.com/api/v3/#grid) supports the ability to obtain a section of the 3m x 3m what3words grid in GeoJSON format, making it very simple to display on a map. This tutorial will show you how to integrate the what3words grid onto Bing Maps. We also have tutorials demonstrating its use with [Google Maps](https://developer.what3words.com/tutorial/displaying-the-what3words-grid-on-a-google-map), [Mapbox](https://developer.what3words.com/tutorial/displaying-the-what3words-grid-on-a-mapbox-map), and [LeafletJS](https://docs.what3words.com/tutorials/grid-leaflet.php). Before you begin developing your application, you need to create a developer account on the [Bing Maps Account Center](https://www.bingmapsportal.com/). A Bing Maps Developer Account allows you to create a Bing Maps Key to use in your map application. Getting a key is described in [Getting a Bing Maps Key](https://docs.microsoft.com/en-us/bingmaps/getting-started/bing-maps-dev-center-help/getting-a-bing-maps-key). [Grid Section Map Overlay (Bing Maps)](https://codesandbox.io/s/displaying-the-what3words-grid-on-a-bing-maps-tpproi) (interactive example) ## 1. Get API key You will need a what3words API key to complete this tutorial. [Get an API Key](https://accounts.what3words.com/select-plan) or [sign in](https://accounts.what3words.com/). ## 2. Installation To load the JavaScript wrapper for the what3words API, use a `script` tag like the one in the following example. Replace `YOUR-API-KEY` with your what3words API key to get started. **Note:** We prefer to use a fixed version of the production version of your integrations. A specific version can also be specified within the script to ensure a predictable version of the component is loaded, for example`@5.0.0`. A log of versions can be found [here.](https://developer.what3words.com/tutorial/javascript-autosuggest-component#versioning) **JavaScript** ```javascript ``` The URL contained in the script tag is the location of a JavaScript file that loads everything you need for using the JavaScript wrapper for the what3words API. The `key` parameter contains your application’s API key. You will also need to add a reference to the map control script of the Bing Maps API. You specify the `key` parameter that contains your [Bing Maps API key](https://docs.microsoft.com/en-us/bingmaps/getting-started/bing-maps-dev-center-help/getting-a-bing-maps-key) as part of the map script URL. The map control can be loaded asynchronously by specifying a callback function in the script URL and by adding “async defer” to the script tag as follows: **JavaScript** ```javascript ``` ## 3. Map style In the `body` of the page, add a `DIV` element to the page to contain the map. The size of the map is defined by the height and width of the DIV element. The position of the map is set by using the “position”, “top”, and “left” properties. You can set these values either inline or by defining the values in a style class and then referencing that class. In this example, we’ll set the map to display full screen, as follows: **JavaScript** ```javascript
``` ## 4. Map initialisation Next, within a new `script` tag, you need to create a function that can be called when your application loads. **JavaScript** ```javascript ``` If loading the map synchronously, you can trigger the `initMap` function by adding it to the `onload` event of the body tag. If you wish to load the map asynchronously please follow this [tutorial](https://docs.microsoft.com/en-us/bingmaps/v8-web-control/creating-and-hosting-map-controls/creating-a-basic-map-control). **JavaScript** ```javascript var map = new Microsoft.Maps.Map('#myMap'); ``` ## 5. Grid overlay The what3words grid can be drawn on top of a Bing Map by calling the what3words Grid API to obtain the grid squares within the currently visible bounding box of the map. Because only a segment of the grid section can be requested, we need to obtain a new grid section each time the map is panned or zoomed. **JavaScript** ```javascript ``` ### Full example The example below takes the step by step guide and puts them into a complete, working example. **JavaScript** ```javascript Displaying the what3words grid on a Bing Maps
``` --- # Combining the what3words.js AutoSuggest Component with a Google Map Adding a what3words address to your website with a Google Map. Topics: JavaScript, Website Section: [Display Map](https://developer.what3words.com/docs/display-map.md) > [Other Map Types](https://developer.what3words.com/docs/display-map/other-map-types.md) Source: https://developer.what3words.com/tutorial/combining-the-what3words-js-autosuggest-component-with-a-google-map Updated: 2026-11-27 ### Step by step The what3words JavaScript API wrapper provides components to make using the what3words API even easier. In this tutorial, we will go through using the autosuggest component in combination with a Google Map. We will add the search field using the component and then respond to its select event to place a pin on the map at the inputted location. You will also need to sign up for a Google Maps developer account and be able to view other Google Maps tutorials at [https://developers.google.com/maps/documentation/javascript/tutorial](https://developers.google.com/maps/documentation/javascript/tutorial). We also have tutorials demonstrating its use with both [Mapbox](https://developer.what3words.com/tutorial/combining-the-what3words-js-autosuggest-component-with-a-mapbox-map) and [LeafletJS](https://developer.what3words.com/tutorial/combining-the-what3words-js-autosuggest-component-with-a-leafletjs-map). ## 1. Get API key You will need a what3words API key to complete this tutorial. [Get an API Key](https://accounts.what3words.com/select-plan) or [sign in](https://accounts.what3words.com/). ## 2. Create an HTML page Define an HTML page to create a map that is the full width and height of the web browser window. Add HTML and CSS to create a page with a map element. The `#map` is the element that displays the map and its CSS resets any browser settings, so it can take the full width and height of the browser. The `` tag is not required in CodeSandbox. If you are using a different editor or running the page on a local server, be sure to add this tag to the top of your HTML page. **HTML** ```html Autosuggest Component (Google Map)
``` ## 3. Reference the APIs In the `` tag, add references to the JS library for the Google Maps API and the JavaScript library for what3words API. You’ll need access to the Google Maps API using your own Google Maps API key. You can also attach the what3words API to the window, which is accessible via `window.what3words`, and set a callback function for it, using  `script` tags like the ones in the following example. Don’t forget to set your what3words API key. **Note:** We prefer to use a fixed version for the Production version of your integrations. A specific version can also be specified within the script to ensure a predictable version of the component is loaded, for example`@5.0.0`. A log of versions can be found [here.](https://developer.what3words.com/tutorial/javascript-autosuggest-component#versioning) **HTML** ```html ... // google js library (replace Google API Key) // what3words js library ... ... ``` ## 4. Loading a map using Google Maps Now you can place the map on the page, centered at a location of your choosing. The `#map` in the `` tag will render the map. **JavaScript** ```javascript ``` ## 5. Position the component on the map Determine the position of the component on the map. **CSS** ```css ``` Tie the component to the styling. Ensure you include `
` within the wrapper to display the map. **HTML** ```html
...
``` In a few lines of code, you can have an input box that will call the what3words AutoSuggest API endpoint. The `api_key` parameter contains your application’s API key. Replace `YOUR-API-KEY` with your what3words API key to get started. [Sign up](https://accounts.what3words.com) to obtain your free API key. **HTML** ```html
``` There are a number of ways you can configure the AutoSuggest component to better suit your use case, including clipping to country and custom validation errors. For more on the AutoSuggest component see the [what3words Autosuggest JavaScript Component](https://developer.what3words.com/tutorial/javascript-autosuggest-component). ## 6. Listen for the select event The code snippet below shows how to use an event listener to detect when a user selects a what3words address from the listed suggestions for their input. For debug purposes, it has been added a console log to show how to retrieve the words of the suggestions: **JavaScript** ```javascript function initW3w(what3words) { ... let words; const autosuggest = document.getElementById("autosuggest"); autosuggest.addEventListener("selected_suggestion", (value) => { let words = value.detail.suggestion.words; // console.log(words); }); ... } ``` ## 7. Convert what3words address to coordinates To convert a what3words address to coordinates, users will need to call the what3words API as shown below. They will need to add this code snippet to the `autosuggest` event listener. **JavaScript** ```javascript function initW3w(what3words) { ... let words; const autosuggest = document.getElementById("autosuggest"); autosuggest.addEventListener("selected_suggestion", (value) => { let words = value.detail.suggestion.words; // what3words api call request what3words.api .convertToCoordinates({ words: words, format: "geojson" }) .then(function (response) { console.log("[convertToCoordinates]", response); }); }); } ``` ## 8. Place a map marker Now that the coordinates of the what3words address are retrieved from the above call to the what3words API, users can place a simple map marker on the map and centre the map on its location. **JavaScript** ```javascript ``` ## 9. Full Example The example below takes the concepts described above and turns some of them into a complete example. Here we have an AutoSuggest component place on a map, where we are listening for the select event. We are then using the what3words JavaScript Wrapper’s convert to coordinates functionality to get the coordinates for that address. With those coordinates we then refocus the map and drop a pin on the location selected. **HTML** ```html Autosuggest Component (Google Maps)
``` --- # Combining the what3words.js AutoSuggest Component with a LeafletJS Map Adding a what3words address input to your website with a LeafletJS Map. Topics: JavaScript, Website Section: [Display Map](https://developer.what3words.com/docs/display-map.md) > [Other Map Types](https://developer.what3words.com/docs/display-map/other-map-types.md) Source: https://developer.what3words.com/tutorial/combining-the-what3words-js-autosuggest-component-with-a-leafletjs-map Updated: 2026-11-27 ### Step by step The JavaScript wrapper for the what3words API provides components to make using the what3words API even easier. In this tutorial, we will show you how to use the AutoSuggest component in combination with a LeafletJS map. We will add the search field using the component and then respond to its select event to place a pin on the map at the inputted location. LeafletJS is an open source mapping engine. More information on LeafletJS can be found at: [https://leafletjs.com/reference-1.5.0.html](https://leafletjs.com/reference-1.5.0.html) We also have tutorials demonstrating its use with both [Mapbox](https://developer.what3words.com/tutorial/combining-the-what3words-js-autosuggest-component-with-a-mapbox-map) and [Google Map](https://developer.what3words.com/tutorial/combining-the-what3words-js-autosuggest-component-with-a-google-map). [Autosuggest Component (Leaflet)](https://codesandbox.io/s/autosuggest-component-leaflet-c8guh) (interactive example) ## 1. Get API key You will need a what3words API key to complete this tutorial. [Get an API Key](https://accounts.what3words.com/select-plan) or [sign in](https://accounts.what3words.com/). ## 2. Create an HTML page Define an HTML page to create a map that is the full width and height of the web browser window. Add HTML and CSS to create a page with a map element. The `#map` is the element that displays the map and its CSS resets any browser settings, so it can take the full width and height of the browser. The `` tag is not required in CodeSandbox. If you are using a different editor or running the page on a local server, be sure to add this tag to the top of your HTML page. **HTML** ```html Autosuggest Component (Leaflet)
``` ## 3. Reference the APIs In the `` tag, add references to the CSS file and JS library for the LeafletJS API and the JavaScript library for what3words API. You can also attach the what3words API to the window, which is accessible via `window.what3words`, and set a callback function for it, using  `script` tags like the ones in the following example. Don’t forget to set your what3words API key. **Note:** We prefer to use a fixed version for the Production version of your integrations. A specific version can also be specified within the script to ensure a predictable version of the component is loaded, for example`@5.0.0`. A log of versions can be found [here.](https://developer.what3words.com/tutorial/javascript-autosuggest-component#versioning) **HTML** ```html ... // what3words JS library // leaflet JS library // leaflet CSS library ... ... ``` ## 4. Loading a map using LeafletJS Now you can place the map on the page, centered at a location of your choosing. The `#map` in the `` tag will render the map. **JavaScript** ```javascript function initW3w(what3words) { ... let map = L.map("map", { zoomControl: false }).setView( [51.520847, -0.195521], 16 ); L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", { attribution: '© OpenStreetMap contributors', maxNativeZoom: 19, maxZoom: 25 }).addTo(map); ... } ``` To Display map navigation controls on the Mapbox map, use `addControl` to add zoom and rotation controls to the map. **JavaScript** ```javascript const nav = new mapboxgl.NavigationControl(); map.addControl(nav, 'bottom-right'); ``` ## 5. Position the component on the map Determine the position of the component on the map. **CSS** ```css ``` Tie the component to the styling. Ensure you include `
` within the wrapper to display the map. **HTML** ```html
...
``` In a few lines of code, you can have an input box that will call the what3words AutoSuggest API endpoint. The `api_key` parameter contains your application’s API key. Replace `YOUR-API-KEY` with your what3words API key to get started. [Sign up](https://accounts.what3words.com) to obtain your free API key. **HTML** ```html
``` There are a number of ways you can configure the AutoSuggest component to better suit your use case, including clipping to country and custom validation errors. For more on the AutoSuggest component see the [what3words AutoSuggest JavaScript Component](https://developer.what3words.com/tutorial/javascript-autosuggest-component). ## 6. Listen for the select event On the code snippet below, it is shown how to use an event listener to detect when a user selects a what3words address from the listed suggestions for their input. For debug purposes, it has been added a console log to show how to retrieve the words of the suggestions: **JavaScript** ```javascript function initW3w(what3words) { ... let words; const autosuggest = document.getElementById("autosuggest"); autosuggest.addEventListener("selected_suggestion", (value) => { let words = value.detail.suggestion.words; // console.log(words); }); ... } ``` ## 7. Convert what3words address to coordinates To convert a what3words address to coordinates, users will need to call the what3words API as shown below. They will need to add this code snippet within the `autosuggest` event listener. **JavaScript** ```javascript function initW3w(what3words) { ... let words; const autosuggest = document.getElementById("autosuggest"); autosuggest.addEventListener("selected_suggestion", (value) => { let words = value.detail.suggestion.words; // what3words api call request what3words.api .convertToCoordinates({ words }) .then(function (response) { console.log("[convertToCoordinates]", response); }); }); } ``` ## 8. Place a map marker Now we have our coordinates we can place a what3words custom marker for our selected what3words address on our map and focus the map on this location. **JavaScript** ```javascript ``` ## 9. Full example The example below takes the concepts described in the step by step guide and turns some of them into a complete example. Here we have an AutoSuggest component place on a map, where we are listening for the select event. We are then using the what3words JavaScript Wrapper’s convert to coordinates functionality to get the coordinates for that address. With those coordinates we then refocus the map and drop a pin on the location selected. **HTML** ```html Autosuggest Component (Leaflet)
``` --- # Combining the what3words.js AutoSuggest Component with a Mapbox Map Adding a what3words address to your website with a Mapbox Map. Topics: JavaScript, Mapbox, Website Section: [Display Map](https://developer.what3words.com/docs/display-map.md) > [Other Map Types](https://developer.what3words.com/docs/display-map/other-map-types.md) Source: https://developer.what3words.com/tutorial/combining-the-what3words-js-autosuggest-component-with-a-mapbox-map Updated: 2026-11-27 ### Step by step The easiest way to add what3words to your technology is to use one of the what3words components. The following tutorial will demonstrate how to integrate the what3words JavaScript component with Mapbox API. The AutoSuggest Component allows users to quickly and correctly input a what3words address to a form input or search field by providing suggestions as a user types and validation to ensure the input value is a valid what3words address. The component by default uses the what3words API, or can be configured to use a privately hosted instance of the what3words API. Please refer to this tutorial to get more information on how to use the [what3words JavaScript AutoSuggest Component](https://developer.what3words.com/tutorial/javascript-autosuggest-component). To access the Mapbox API, users will need to sign up for a Mapbox developer account and create an API key. If you are new to Mapbox API, start with the [MapBox GL JS API documentation](https://docs.mapbox.com/mapbox-gl-js/api/). We also have tutorials demonstrating its use with both [LeafletJS](https://developer.what3words.com/tutorial/combining-the-what3words-js-autosuggest-component-with-a-leafletjs-map) and [Google Map](https://developer.what3words.com/tutorial/combining-the-what3words-js-autosuggest-component-with-a-google-map). [Autosuggest Component (Mapbox)](https://codesandbox.io/s/autosuggest-component-mapbox-sdh68) (interactive example) ## 1. Get API key You will need a what3words API key to complete this tutorial. [Get an API Key](https://accounts.what3words.com/select-plan) or [sign in](https://accounts.what3words.com/). ## 2. Create an HTML page Define an HTML page to create a map that is the full width and height of the web browser window. Add HTML and CSS to create a page with a map element. The `#map` is the element that displays the map and its CSS resets any browser settings, so it can take the full width and height of the browser. The `` tag is not required in CodeSandbox. If you are using a different editor or running the page on a local server, be sure to add this tag to the top of your HTML page. **HTML** ```html Autosuggest Component (Mapbox)
``` ## 3. Reference the APIs In the `` tag, add references to the CSS file and JS library for the Mapbox API and the JavaScript library for what3words API. The CSS file is required to display the map and make elements like Popups and Markers work. You can also attach the what3words API to the window, which is accessible via `window.what3words`, and set a callback function for it, using  `script` tags like the ones in the following example. Don’t forget to set your what3words API key. **Note:** We prefer to use a fixed version for the Production version of your integrations. A specific version can also be specified within the script to ensure a predictable version of the component is loaded, for example`@5.0.0`. A log of versions can be found [here.](https://developer.what3words.com/tutorial/javascript-autosuggest-component#versioning) **HTML** ```html ... // mapbox js library // what3words js library // mapbox css file ... ... ``` ## 4. Loading a map using Mapbox Now you can place the map on the page, centered at a location of your choosing. The `#map` in the `` tag will render the map. **JavaScript** ```javascript function initW3w(what3words) { ... mapboxgl.accessToken = YOUR_MAPBOX_ACCESS_TOKEN; const map = new mapboxgl.Map({ container: 'map', style: 'mapbox://styles/mapbox/streets-v9', center: [-0.195499, 51.52086], zoom: 12 }); ... } ``` To Display map navigation controls on the Mapbox map, use `addControl` to add zoom and rotation controls to the map. **JavaScript** ```javascript const nav = new mapboxgl.NavigationControl(); map.addControl(nav, 'bottom-right'); ``` ## 5. Position the component on the map Determine the position of the component on the map. **CSS** ```css html, body, #map { position: absolute; height: 100%; width: 100%; margin: 0; padding: 0; } #autosuggest { position: absolute; top: 10px; left: 10px; z-index: 100; } #wrapper { position: relative; height: 100%; } ``` Tie the component to the styling. Ensure you include `
` within the wrapper to display the map. **HTML** ```html
...
``` In a few lines of code, you can have an input box that will call the what3words AutoSuggest API endpoint. The `api_key` parameter contains your application’s API key. Replace `YOUR-API-KEY` with your what3words API key to get started. [Sign up](https://accounts.what3words.com) to obtain your free API key. **HTML** ```html
``` ## 6. Listen for the select event The code snippet below shows how to use an event listener to detect when a user selects a what3words address from the listed suggestions for their input. For debug purposes, it has been added a console log to show how to retrieve the words of the suggestions: **JavaScript** ```javascript function initW3w(what3words) { ... let words; const autosuggest = document.getElementById("autosuggest"); autosuggest.addEventListener("selected_suggestion", (value) => { let words = value.detail.suggestion.words; // console.log(words); }); ... } ``` ## 7. Convert what3words address to coordinates To convert a what3words address to coordinates, users will need to call the what3words API as shown below. They will need to add this code snippet within the `autosuggest` event listener. **JavaScript** ```javascript function initW3w(what3words) { ... let words; const autosuggest = document.getElementById("autosuggest"); autosuggest.addEventListener("selected_suggestion", (value) => { let words = value.detail.suggestion.words; // what3words api call request what3words.api .convertToCoordinates({ words: words, format: "geojson" }) .then(function (response) { console.log("[convertToCoordinates]", response); }); }); } ``` ## 8. Place a map marker Now that the coordinates of the 3 words address are retrieved from the above call to the what3words API, users can place a simple map marker on the map and centre the map on its location. **JavaScript** ```javascript ``` Add a marker element to the CSS code snippet within the ``. **CSS** ```css .marker { background-image: url("https://what3words.com/map/marker.png"); background-size: cover; width: 64px; height: 64px; cursor: pointer; } ``` ## 9. Full example The example below takes the concepts described in the step by step guide and turns some of them into a complete example. Here we have an AutoSuggest component place on a map, where we are listening for the select event. We are then using the what3words JavaScript Wrapper’s convert to coordinates functionality to get the coordinates for that address. With those coordinates we then refocus the map and drop a pin on the location selected. **HTML** ```html Autosuggest Component (Mapbox)
``` --- # Import and Plot what3words Addresses on the Map Site using a CSV File This tutorial explains how to import and organise what3words addresses using a CSV file on the Map Site, resolve common errors, and sync locations to the mobile app. Topics: Website Section: [Display Map](https://developer.what3words.com/docs/display-map.md) > [Other Map Types](https://developer.what3words.com/docs/display-map/other-map-types.md) Source: https://developer.what3words.com/tutorial/import-and-plot-what3words-addresses-on-the-map-site-using-a-csv-file Updated: 2026-11-27 This guide explains how to use the **Import CSV** and **Export CSV** features on the what3words Map Site to upload, plot, and manage what3words addresses. Once plotted, these addresses can also be accessed and viewed on the what3words mobile app. For a visual guide, you can refer to the following video: [Watch this walkthrough on YouTube](https://www.youtube.com/watch?v=yJPjocn86s0) ## 1. Preparing Your CSV File Before importing your data, ensure your CSV file is formatted correctly with the required headers. **Required Column Headers:** - `List`: Organise your locations into categories (e.g., “Personal” or “Work”). - `3 word address`: Valid what3words addresses (e.g., filled.count.soap or ///filled.count.soap). - `Label`: Add a descriptive name or note for each location (e.g., “Home Address”). **Example CSV Structure:** **CSV** ```csv List,3 word address,Label Work,filled.count.soap,Office Location Personal,index.home.raft,Home Address Other,scar.jazzy.offers,Park Entrance ``` This CSV file creates three lists (Work, Personal, Other) with one labelled location each, plots them on the map, and syncs them to the mobile app. Save your file in `.csv` format using a text editor or spreadsheet tool like Excel or Google Sheets. An example of this template can also be downloaded here is [Download Template](https://drive.google.com/file/d/1wMZyZQ8tputv5barH3tR6-NXHQPv_MHf/view?usp=drive_link) **Note:** You can also get this template by visiting the mapsite and following step 2. ## 2. Importing your CSV File to the Map 1. Open the [what3words Map Site;](https://what3words.com) 2. Log in to your what3words account. This step is essential to sync your data with the mobile app; 3. Click the Menu (three horizontal lines in the top-right corner); 4. Click “Saved Locations”; 5. Click the tree dots icon in the top-right corner of My Lists; 6. Select “Import lists from CSV”; 7. In the pop-up window: – Click “Upload CSV” button to upload your formatted file; – Or Click “Download template” to get the CSV template from the mapsite; 8. Your what3words addresses will now appear as markers on the map. ## 3. Viewing Locations on the Mobile App After importing your data: 1. Open the what3words mobile app on your device; 2. Log in with the same account used on the Map Site; 3. Navigate to the map view: Your imported what3words addresses will appear as synced markers; 4. Tap on a marker to view details, including the Label and List information you added. ## 4. Exporting Your Data If you’ve updated or modified your plotted data on the Map Site, you can export it for further use: 1. Go back to the Menu on the Map Site; 2. Go to Saved Locations > 3 dots icon in the top-right corner of My Lists; 3. Select “Export Lists to CSV”; 4. Download the generated CSV file containing these columns `List`, `3 word address` and `Label`; 5. Save this file for sharing or future use. ## 5. Troubleshooting Below is a table summarising the common errors users might encounter when importing a CSV file to save locations and how to address them: | Error Code | Message | Meaning | Resolution | | --- | --- | --- | --- | | 601, 702, 823 | “An error occurred, please contact support@what3words.com.” | A generic error occurred that is not mapped to a specific issue. | Contact what3words support at support@what3words.com for assistance. | | 824 | “CSV import would exceed maximum saved location limit.” | The number of saved locations would exceed the account limit. The Limit is 1000 saved locations. | Reduce the number of locations in the CSV file and try again. | | 825 | “Row ${rowNumber} contains an invalid 3 word address. 3 word address provided ${w3wAddress}.” | A 3-word address in the specified row of the CSV file is invalid. | Verify and correct the invalid 3-word address in the CSV file. | | 826 | “Row ${rowNumber} contains a duplicate 3 word address. Duplicate address ${w3wAddress}.” | The 3-word address in the specified row already exists as a saved location. | Remove the duplicate address from the CSV file or update the existing saved location if needed. | | 827 | “Row ${rowNumber} contains an invalid number of fields.” | A row in the CSV file has an incorrect number of fields or columns. | Ensure all rows in the CSV file have the correct number of columns as per the template. | **Table Notes** Dynamic Data in Messages: - `${rowNumber}` is dynamically populated with the row number in the CSV file where the error occurred. - `${w3wAddress}` is dynamically populated with the specific invalid or duplicate 3-word address. Default Errors: If the error code is not explicitly handled, it falls back to a generic message instructing the user to contact support. ### How to Handle Errors During CSV Import 1. **Check the Error Message** – After attempting to import your CSV file, review the error message displayed. It will indicate the specific issue, such as a problem with a particular row or a general import limitation. 2. **Understand the Error **– Use the table above to identify the error’s meaning and how it can be resolved. 3. **Correct the CSV File **– Open your CSV file in a text editor or spreadsheet software; – Remove or reorganise entries to stay within account limits; – Navigate to the row indicated in the error message (if applicable); – Make the necessary changes: Fix invalid or duplicate 3-word addresses; Ensure all rows have the correct number of fields. 4. **Re-upload the File **– Save your corrected CSV file in .csv format. – Retry the import process. 5. **Contact Support if Needed** – If you encounter errors that persist or are unclear, contact what3words support at [support@what3words.com](mailto:support@what3words.com) for further assistance. ## 6. FAQs ### Do I need an account to use Import/Export features? Yes, you must log in to your what3words account to sync data between the Map Site and the mobile app. ### Can I view imported data offline in the mobile app? You’ll need an internet connection to sync the imported data. Once synced, locations are cached for offline access. ### What if my CSV file has errors? The system will display an error message, please check the errors in the table mentioned above. Ensure your file: - Includes a valid 3 word address column; - Is saved in .csv format; - It has a limit of 1000 saved locations; - It has the current number of columns: List, 3 word address, Label; - It doesn’t contain duplicated what3words addresses. ### Can I organise locations into lists using the CSV file? Yes, use the List column to group locations by category (e.g., Work, Personal). ### Can I import a CSV file with more than 1,000 rows? No, the maximum allowed rows per account is 1,000. ### Will the imported locations sync with my mobile app? Yes, as long as you’re logged into the same what3words account on both the Map Site and the mobile app. ### Will the csv import if I have different headers column? It won’t import the what3words address on the what3words online map site if you don’t follow the .CSV template structure. The column headers should be: `List`, `3 word address`, `Label`.