Location picker
Let users pick a spot by moving the map under a fixed pin, and look up its address
Delivery and ride-hailing apps often keep a pin in the middle of the map and let users move the map under it. When the map stops, this example reads the center and looks up its address:
Looking up the address…
How it works
- The pin is an element on top of the map with
pointer-events: none, so dragging still moves the map. onViewChangereports the center once the map stops moving, so there's one lookup per move instead of one per frame.address()fromuseSearchturns the center into an address. An answer for an older center is ignored, so a slow lookup never replaces a newer one.
Addresses need the address service enabled for your API key. Without it, address() resolves null, and the example tells users so.
To let users search first, add useSuggest and move the map to the chosen place with goTo.