Select to view content in your preferred language

Using Near Me Without Looking At Near Me: Triggering Near Me From A Search Bar And Sending The Results To A List (Also, Hidden Widgets)

819
0
01-19-2024 12:18 PM
JeffreyThompson2
MVP Regular Contributor
4 0 819

When Near Me came out last summer, I was pretty excited. At the time I was working on a public facing application where people could filter a list of parks by their amenities to figure out which one they should go to. And it would be so nice, if they could put in their address and get the list sorted by their location. But, I was very disappointed by the actual implementation of the Near Me Widget. I wrote up my complaints on the ideas board here, but to summarize I just don't like the user interface of Near Me, especially for a public facing application, and I don't want to give up more screen space to Near Me when I already have a well-designed List Widget. I ended my rant on the Ideas board with this:

For my application, the ideal Near Me widget would just be a search bar with a current location button next to it. The user could enter an address or press the button and see the results in the list widget.

Well, since the October 2023 ArcGIS Online update, it is now possible to build that (or something pretty close to it). Here's how...

Step One: Triggering Near Me From Search

For this recipe, we will need a Map Widget, a Search Widget, a Near Me Widget and a List Widget. Let's drag them all into our Experience now and we'll set them up as we go. Start with your Map Widget and select the webmap you want to use. Then, go the Search Widget and pick a locator source. You'll also want to open the Search Suggestion options and check the Use Current Location option.

JeffreyThompson2_0-1705682163840.png

In the Action Tab, add a Record Selection Changes > Near Me > Set Location Action. (A Map > Zoom To Action is not necessary, but you'll probably want it, too.)

Step Two: Set Up Near Me

First, I select my Map Widget. At this point, Near Me will display this scary and confusing warning.

JeffreyThompson2_2-1705683787701.png

This is normal. Near Me is asking you to click on the name of your map again to open up the Analysis settings menu.

In the Analysis settings menu, pick Specify a location, set some sort of buffer distance (I went with 5 miles.) and the click the Add Analysis button. 

JeffreyThompson2_1-1705683701917.png

In the next window, I picked Analysis Type > Proximity and Sort features > Distance. (I also turned off Highlight results on map.)

JeffreyThompson2_3-1705684445191.png

I also opened the General Settings and set the Sketch Color to rgba(255,255,255,0). (Translation: transparent white.) In testing, I found that the default transparent option made a dark grey circle that was actually still very noticable, but by using transparent white there was just a faint dimming of the map and a barely visible edge of the circle.

Step Three: Send Near Me Results To A List Widget

In the List Widget, click Select Data > Outputs > Near Me > Whatever I Named My Near Me Output. (I'm also going to add a No data message to tell the user to use the Search Widget.) 

JeffreyThompson2_0-1705688892256.png

And there we go, when I search in the search bar the data will be transferred to this List. Style up your List Widget as you see fit. (Here's a post about all the various List Widget options.)

But, why? What was the point of all of this?

  1. A well designed List Widget just looks better and is easier to use than the Near Me Widget interface.
  2. Now that the data is in a List Widget, I can do all the stuff that the List Widget can do including, but not limited to, searching, sorting and filtering within the list, sending to a table, and exporting as CSV, JSON or geoJSON. Near Me can only do one of those things: download as a CSV.

Step Four: Hiding Near Me (Hiding The Widget, Not Hiding Close To Me. That's Creepy. Don't Do That.)

At this point, we have a Search Widget that automatically fills Near Me results into a List Widget. We don't need to look at the Near Me Widget anymore. So what can we do with it? Delete it? Send it to the Pending List? Stick it in a Section or Widget Controller? No, doing any of those things would break this build. We are going to do something far stupider. We are going to make it tiny. In the Style Tab of the Near Me settings, set the Width and Height to 0px. Experience Builder won't truly honor my 0 x 0px request. It seems that the true minimum widget size is 16 x 16px.

JeffreyThompson2_1-1705691421127.png

See that tiny box I circled in red. That's my Near Me Widget. It will happily do its job even if the user can't read anything in it. Should I need to alter any of my Near Me options later, I can click my little box and the settings panel will appear.

If I was on Developer Edition right now, I'd add this to my CSS to make that little box vanish completely.

 

.widget-near-me {
   display: none;
}

But we all know using Developer Edition is cheating, what can we do in ArcGIS Online?

Well, we could be happy with our tiny box taking up some unimportant part of the screen, but if you really want it hidden. You can use a Sidebar Widget.

I've put my tiny Near Me Widget in the collapsable side of a Sidebar Widget. Set its size to 0px, Default state to Collapsed and turned off the Collapse Button.

JeffreyThompson2_0-1705692929103.png

Tiny Near Me will happily keep doing its job banished to an undefinably thin, unopenable Sidebar Widget and your users will never know exists (unless they inspect your page with their browser's Dev Tools).

I have found hidden custom widgets to be very useful before, but this is my first time hiding a default widget. I've had a flood of ideas during the writing of this post (including that unopenable Sidebar trick) and I think there may be some sequels to this post coming soon. What could you do with a hidden Views Navigation or Timeline Widget? 

I am making my demo app publicly available, so you can decide if a Near Me-free Near Me is right for you. The big downside is that I can't find a way to make my List Widget a list of all parks in absence of a Near Me search. (I attempted using the Filter Layers To Only Show Results option within Near Me, but did not get the results I wanted.) Another potential downside is reducing the end user's Near Me options. This demo still doesn't work well enough to have been used in my original park application, but in my opinion, it is a lot closer.

 

About the Author
A frequently confused rock-hound that writes ugly, but usually functional code.