Select to view content in your preferred language

reverse geocode doesnt update the box(Directions widget). Clicking to add a point also adds at coordinates instead of address

2762
4
10-20-2015 04:24 AM
lasinh
by
Occasional Contributor

i used The Directions widget arcgis api javascript, but when i click on map,  reverse geocode doesnt update the box(Directions widget), Clicking to add a point also adds at coordinates instead of address. (I am using my own geocoding, geometry and routing services) .how to update address to box? thank you;

my code:

<!DOCTYPE html>

<html>

  <head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">

    <title>Directions Widget</title>

    <link rel="stylesheet" href="http://js.arcgis.com/3.14/dijit/themes/claro/claro.css">

    <link rel="stylesheet" href="http://js.arcgis.com/3.14/esri/css/esri.css">

    <style>

      html, body, #map {

        height:100%;

        width:100%;

        margin:0;

        padding:0;

      }

      body {

        background-color:#FFF;

        overflow:hidden;

        font-family:"Trebuchet MS";

      }

    </style>

    <script src="http://js.arcgis.com/3.14/"></script>

    <script>

      require([

        "esri/urlUtils", "esri/map", "esri/dijit/Search",  "esri/tasks/locator", "esri/dijit/Directions",

        "dojo/parser",

        "dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dojo/domReady!"

      ], function(

        urlUtils, Map, Search,  Locator,  Directions,

        parser

      ) {

        parser.parse();

        //all requests to route.arcgis.com will proxy to the proxyUrl defined in this object.

        var strPathService = "http://115.79.20.1:6080/arcgis/rest/services/";

          map = new Map("map", {

              zoom: 6,

            

          });

          var tiled = new esri.layers.ArcGISDynamicMapServiceLayer(strPathService + "Bandochuyende/numberhouse/MapServer");

          map.addLayer(tiled);

        //travelModesServiceUrl option points to logistics service hosted from ArcGIS Online

        //by indicating this URL, a login prompt should not display

        var directions = new Directions({

          map: map,

           mapClickActive: true,

          searchOptions: {

             sources: [

               {

               locator: new Locator(strPathService + "Geocode/GEOCODING_SONHA_BH/GeocodeServer"),

   

                     name: "Custom Geocoding Service",

                     localSearchOptions: {

                     minScale: 3000000,

                       distance: 500000

                     },

                     placeholder: "Search Geocoder",

                     maxResults: 3,

                     maxSuggestions: 6,

                     enableSuggestions: false,

                     minCharacters: 0

                 }

                 ]

                 },

          //travelModesServiceUrl: "http://utility.arcgis.com/usrsvcs/servers/cdc3efd03ddd4721b99adce219629489/rest/services/World/Utili...",

       routeTaskUrl: strPathService + "NetworkRouter/network01102015/NAServer/Route"

        },"dir");

        directions.startup();

      });

    </script>

  </head>

  <body class="claro">

    <div data-dojo-type="dijit/layout/BorderContainer"

         data-dojo-props="design:'headline', gutters:false"

         style="width:100%;height:100%;">

      <div data-dojo-type="dijit/layout/ContentPane"

           data-dojo-props="region:'right'"

           style="width:250px;">

       

        <div id="dir"></div>

      </div>

      <div id="map"

           data-dojo-type="dijit/layout/ContentPane"

           data-dojo-props="region:'center'">

      </div>

    </div>

  </body>

</html>

0 Kudos
4 Replies
TyroneBiggums
Deactivated User

Note the use of location-to-address-complete here:

https://developers.arcgis.com/javascript/jssamples/locator_reverse.html

0 Kudos
lasinh
by
Occasional Contributor

thanks repply!! usinguse location-to-address-complete updated list of stops or not? how to update stops box directions widget?

0 Kudos
TyroneBiggums
Deactivated User

Full disclosure, I'm not familiar with the directions widget. I've only used aspects of it. Once a location for A and B was entered, the up/down arrow button switches A and B. Other than that, I don't know about updating the stops/addresses.

The link that I provided is for taking the coordinates that are showing up for A and B on the reverse geocoder, and providing an address. I only addressed that part of your question.

If you tell me what you mean by updating stops, I might be able to take a peak later.

0 Kudos
lasinh
by
Occasional Contributor

i used location-to-address-complete get address to box, but My code does not work as expected, please help me, thank you!!!

<!DOCTYPE html>

<html>

  <head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">

    <title>Directions Widget</title>

    <link rel="stylesheet" href="http://js.arcgis.com/3.14/dijit/themes/claro/claro.css">

    <link rel="stylesheet" href="http://js.arcgis.com/3.14/esri/css/esri.css">

    <style>

      html, body, #map {

        height:100%;

        width:100%;

        margin:0;

        padding:0;

      }

      body {

        background-color:#FFF;

        overflow:hidden;

        font-family:"Trebuchet MS";

      }

    </style>

    <script src="http://js.arcgis.com/3.14/"></script>

    <script>

        require([

        "esri/urlUtils", "esri/map", "esri/dijit/Search", "esri/graphic", "esri/Color",

        "esri/InfoTemplate", "esri/geometry/webMercatorUtils", "esri/tasks/locator", "esri/symbols/SimpleMarkerSymbol", "esri/symbols/SimpleLineSymbol", "esri/dijit/Directions",

        "dojo/parser",

        "dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dojo/domReady!"

      ], function (

        urlUtils, Map, Search, Graphic, Color, InfoTemplate, webMercatorUtils, Locator, SimpleMarkerSymbol, SimpleLineSymbol, Directions,

        parser

      ) {

          parser.parse();

          //all requests to route.arcgis.com will proxy to the proxyUrl defined in this object.

          var strPathService = "http://115.79.20.1:6080/arcgis/rest/services/";

          map = new Map("map", {

              zoom: 6

          });

          var infoTemplate = new InfoTemplate("Location", "Address: ${Street}");

          var symbol = new SimpleMarkerSymbol(

          SimpleMarkerSymbol.STYLE_CIRCLE,

          15,

          new SimpleLineSymbol(

            SimpleLineSymbol.STYLE_SOLID,

            new Color([0, 0, 255, 0.5]),

            8

          ),

          new Color([0, 0, 255])

        );

          var tiled = new esri.layers.ArcGISDynamicMapServiceLayer(strPathService + "Bandochuyende/numberhouse/MapServer");

          map.addLayer(tiled);

          var locator = new Locator(strPathService + "Geocode/GEOCODING_SONHA_BH/GeocodeServer");

          //travelModesServiceUrl option points to logistics service hosted from ArcGIS Online

          //by indicating this URL, a login prompt should not display

          var directions = new Directions({

              map: map,

              mapClickActive: true,

              searchOptions: {

                  sources: [

               {

                   locator: locator,

                   name: "Custom Geocoding Service",

                   localSearchOptions: {

                       minScale: 3000000,

                       distance: 500000

                   },

                   placeholder: "Search Geocoder",

                   maxResults: 3,

                   maxSuggestions: 6,

                   enableSuggestions: false,

                   minCharacters: 0

               }

                 ]

              },

              //travelModesServiceUrl: "http://utility.arcgis.com/usrsvcs/servers/cdc3efd03ddd4721b99adce219629489/rest/services/World/Utili...",

              routeTaskUrl: strPathService + "NetworkRouter/network01102015/NAServer/Route"

          }, "dir");

          directions.startup();

          locator.on("location-to-address-complete", function (evt) {

              if (evt.address.address) {

                  var address = evt.address.address;

                  var location = evt.address.location;

                  //this service returns geocoding results in geographic - convert to web mercator to display on map

                  // var location = webMercatorUtils.geographicToWebMercator(evt.location);

                  var graphic = new Graphic(location, symbol, address, infoTemplate);

                  map.graphics.add(graphic);

                  for (var i = 0; i <= directions.stops.length - 1; i++) {

                      directions.stops.name = evt.address.address.Street;

                  }

                  map.infoWindow.setTitle(graphic.getTitle());

                  map.infoWindow.setContent(graphic.getContent());

                  //display the info window with the address information

                  var screenPnt = map.toScreen(location);

                  map.infoWindow.resize(200, 100);

                  map.infoWindow.show(screenPnt, map.getInfoWindowAnchor(screenPnt));

              }

          });

          map.on("click", function (evt) {

              map.graphics.clear();

              locator.locationToAddress(evt.mapPoint, 100);

          });

      });

    </script>

  </head>

  <body class="claro">

    <div data-dojo-type="dijit/layout/BorderContainer"

         data-dojo-props="design:'headline', gutters:false"

         style="width:100%;height:100%;">

      <div data-dojo-type="dijit/layout/ContentPane"

           data-dojo-props="region:'right'"

           style="width:250px;">

      

        <div id="dir"></div>

      </div>

      <div id="map"

           data-dojo-type="dijit/layout/ContentPane"

           data-dojo-props="region:'center'">

      </div>

    </div>

  </body>

</html>

0 Kudos