Geocode and return results

290
6
Jump to solution
02-27-2020 08:06 AM
jaykapalczynski
Frequent Contributor

Initial Need: The user selects a point in the map and that defines the address in the form

I am looking for a solution that provides a certain level of interaction between a traditional web form and leveraging the ESRI JS api.  What I am trying to do is proof a concept where a user can leverage the Find Address example below:

Search for an address | ArcGIS for Developers 

I created this JS fiddle with some modifications to the example above 

https://jsfiddle.net/Jaykapalczynski/6e0snvyr/3/

Edit fiddle - JSFiddle - Code Playground 

In this example the user can click on the map.

This will geocode the Map Location and return an address and XY to variables

I can then use these variables to populate a couple textareas and most importantly to populate a Form on the page.

This works great.

ALTHOUGH - If I use the Find Address input box from the search widget I can enter and address and get the result in a popup.  While this appears to solve my needs, I need to capture that Address and XY being returned to the popup (I am assuming the XY location is available some how.)  I do NOT want the user to have to interact with the map...ONLY the Find Address input box.  I cant seem to find a way to grab the results from the geocoding that are sent back via the Find Address or Place geocoder

Questions:

1. What I am having an issue with is .... capturing the result from the Find Address or Place search and th resulting popup that appears after the search is done (NOT a map click)....and writing those values (address, X, Y) to variables that I can split and push to the forms input boxes.

2. Is there a way to JUST display the "Find Address or Place" input box and get rid of the map and zoom tools?  Or do I have to create a new widget?  I dont care about the map and zoom tools.

If I have to create my own GP Service and handle the communication back and forth I will do so...but just thought this might be easier.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

Jay,

    search.on("select-result", function (event) {
      console.log(event.result.name, event.result.feature.geometry.x, event.result.feature.geometry.y);
    });‍‍‍

View solution in original post

6 Replies
jaykapalczynski
Frequent Contributor

Trying this 

Console.log gives me this

First alert gives me

         [object Object]

Second alert does NOT show up.

Just need to get the Match Address and XY back...ugggg

    // Search widget
    var search = new Search({
        view: view,
    });

        search.on("select-result", function (event) {
            console.log("The selected search result: ", event);

            test = event;
            alert(test);

            var vtest = event;
            var vreturn = JSON.stringify(vtest);
            alert(vreturn);

        });
0 Kudos
jaykapalczynski
Frequent Contributor

I changed it to SEARCH-COMPLETE and I can get the number of results and the search term but I cant find out how to read the XY coordinates and the Match Address from the actual geocode?

Anyone?

// Search widget
var search = new Search({
view: view,
popupEnabled: false
});

search.on("search-complete", function (event) {

testnumber = event.numResults;
alert(testnumber);

//test = JSON.stringify(event.searchTerm);
test = event.searchTerm;
alert(test);


});
0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Jay,

    search.on("select-result", function (event) {
      console.log(event.result.name, event.result.feature.geometry.x, event.result.feature.geometry.y);
    });‍‍‍
jaykapalczynski
Frequent Contributor

Dang I was dancing all around the solution...thank you much

last question....when I use the example above (js fiddle) and click on the map and it gives me decimal degrees...

When I use the input box to geocode the entered address it appears to be returning the coordinates in Web Aux Mercator?  Is there a parameter I can set to return the coordinates into decimal degrees?

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Jay,

  Sure just change geometry.x to geometry.longitude and geometry.y to geometry.latitude

jaykapalczynski
Frequent Contributor

THANK YOU once again....very appreciated.

0 Kudos