Live preview

Interactive example

Loading example…

Usage

Import the component and its manager, then make it your own.

ComponentLocationInput
Managercreate_location_input_manager

svelte

<script>
  // Import the shared stylesheet once in your application's root layout.
  import "sveltekit-ui/style.css"
  import { LocationInput, create_location_input_manager, Json, create_json_manager } from "sveltekit-ui"

  // Replace this placeholder with your public MapKit JS token,
  // authorized for your website's domain.
  const public_mapkit_token = "YOUR_DOMAIN_AUTHORIZED_PUBLIC_MAPKIT_TOKEN"

  const place = {
    name: "Boston, Massachusetts",
    latitude: 42.3603,
    longitude: -71.0573,
    formatted_address: "Boston, MA, United States",
    country_code: "US",
  }

  const value_json = create_json_manager({ val: place, is_show_buttons: true })

  const manager = create_location_input_manager({
    val: place,
    mapkit_js_token: () => public_mapkit_token,
    label: "Meeting location",
    is_popover: true,
    is_popover_button: true,
    on_finish: (value) => value_json.set_val(value),
  })
</script>

<LocationInput {manager} />
<Json manager={value_json} />

API reference

Configure the manager, call its methods, and read its reactive state.

10 entries in configuration

PropertyTypeDefaultDescription
valobject or null nullCurrent location data (place_id, latitude, longitude, etc.). If non-null, will be used for initial map view.
mapkit_js_tokenstring nullMapKit JS token for Apple Maps usage.
is_popoverboolean trueIf true, the component is rendered in a popover (centered modal).
is_popover_buttonboolean falseIf true, shows a button that opens the map popover, rather than rendering inline.
is_show_searchboolean trueIf true, includes a search box for place name/POI/address search.
labelstring or null nullLabel text displayed near the location input.
heightnumber (REM) or null nullMap container height. If null, defaults to 'min(40rem, 50vh)'.
widthnumber (REM) or null nullMap container width. If null, defaults to 'clamp(60rem, 80vw, 100%)'.
is_dark_color_schemeboolean falseSets the initial map color scheme (light or dark).
on_finishfunction —Optional callback, called with final location data when finishing.