Hello I am attempting to add a form to an existing html that allows the user to type in a search term and query and existing ArcGIS Online map. For example, a person would enter a coordinate into the form such as:
The resulting url should be (unencoded) : www.arcgis.com/apps/webappviewer/index.html?find=-112.111 33.3456
encoded it should look like: www.arcgis.com/apps/webappviewer/index.html?find=-112.111%2033.3456
The problem is that because the parameter (find) is after the "?" the whitespace in the url is encoded with a "+" instead of "%20". The url becomes: www.arcgis.com/apps/webappviewer/index.html?find=-112.111+33.3456
This causes the feature search to search for : which results in not finding the coordinate.
Solved! Go to Solution.
document.getElementById("search_input").value = document.getElementById("search_input").value.replace("+", ", ")
var findParam = document.getElementById("lat-lon-input-field").value
var rootAppURL = "https://myapp.com/app"
encodedURL = encodeURI( rootAppURL + "?find=" + findParam)
window.location = encodedURL
Hopefully one of those methods answers your original question.
*There are cleaner ways to write this code, but that should get you started.
Why are you using a space between the lat and lon? The documentation states use a comma or semicolon:
You can use commas or semicolons as separators. Use semicolons if your numbers use colons as their decimals.
Thanks Robert for the input on the spaces. Spaces are accepted and that is the way that non-GIS personnel are used to. In addition, spaces are needed to enter an address in to the HTML form which is then passed incorrectly into the query string of the URL. Basically, if the attribute that is needed to be entered into the URL after the ?find= has a space in it then it will fail to find the feature with the + symbol substituted for the space.
I am really confused where the plus is coming from. The substituting of a space with a plus is not a normal encoding method that I am aware of. What does your from html and or JS look like?