Search widget not working

421
1
03-27-2022 09:59 AM
NilrajShrestha
New Contributor

I have been following this tutorial.

https://developers.arcgis.com/javascript/latest/search-for-an-address/

The search bar does not work

Javascript-API

require([
  "esri/config",
  "esri/Map",
  "esri/views/MapView",

  "esri/widgets/Search"

], function(esriConfig,Map, MapView, Search) {

esriConfig.apiKey = "YOUR_API_KEY";

const map = new Map({
    basemap: "arcgis-imagery"
  });

const view = new MapView({
    container: "viewDiv",
    map: map,
    center: [-122.3321,47.6062],
    zoom: 12
  });

const search = new Search({  //Add Search widget
    view: view,
    includeDefaultSources: true,
    locationEnabled: true,
  });

  view.ui.add(search, "top-right"); //Add to the map

});

HTML
 
{% load static%}
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>ArcGIS API for JavaScript Tutorials: Display a map</title>
   
    <link rel="stylesheet" href="https://js.arcgis.com/4.23/esri/themes/light/main.css">
    <link rel="stylesheet" href="{% static '/css/map.css' %}">
    <script src="https://js.arcgis.com/4.23/"></script>
  </head>
  <body>
    <div id="viewDiv" class="viewDiv"></div>
    </div>
    <script src="{% static '/js/arc.js' %}"></script>
   
   
  </body>
</html>
Tags (2)
0 Kudos
1 Reply
ReneRubalcava
Frequent Contributor

Did you add your own API Key to your code? Is there a particular error that shows in the console?

0 Kudos