Hi All
I'm developing a routing app using the JS API. One thing I'm looking at trying to implement is having a search box (to find an address) add a stop to create a route.
Currently, I have the search working, it is using our own Geocoding server (not ESRIs) and the Geocoder Widget. It is displaying and zooming to the the location as a point on the map. To perform the routing I am using routeTask. I can input stops by clicking on the map and then solve the route using a button.
What I would like to be able to do is have the user search for an address, the map zoom to the location. They can then click a button to have the point added as a location on the map. I thought I might be able to use returned JSON but the only thing returned in the console is the GET function getting the new tiles for the area I've zoomed too.
If anyone has an idea of how to achieve this, it would be greatly appreciated.
Thanks
Hamish
Solved! Go to Solution.
Cheers for that, I ended up working out a way which would make it work. I declared a variable
var searchLocation = [0,0];
Then in the function which displays my results on the map I added the x,y results to the array.
searchLocation[0] = evt.result.feature.geometry.x; searchLocation[1] = evt.result.feature.geometry.y;
This works well (I think - it hasn't broken yet) and it allows me to use the coordinates anywhere.
Cheers for your anyway!
Hamish
Hamish,
Check out the code here: Geocode an address | ArcGIS API for JavaScript
Instead of adding a graphic within the showresults function, you can set all the variables within that function and then add the map.graphics.add(graphic); command in your button click function.
Hope this helps!
tim
Hi Tim,
Thanks for that. So instead of using the Geocoder Widget, use Locator instead?
Hamish
To add to that, It would be good to be able to use the geocoder, as this has a number of useful features such as autocomplete. Can something like this be implemented with Locator?
Hamish,
my bad for some reason I thought they were using the address locator.
You can check out my app here, where I use the geocoder (with autocomplete) and a graphic to show where the address is.
Location, Location, Location... - JSFiddle
Especially this part of my code:
geocoder.on("select", showLocation);
and the showLocation function associated with this.
Hope this helps!
Tim
Cheers for that, I ended up working out a way which would make it work. I declared a variable
var searchLocation = [0,0];
Then in the function which displays my results on the map I added the x,y results to the array.
searchLocation[0] = evt.result.feature.geometry.x; searchLocation[1] = evt.result.feature.geometry.y;
This works well (I think - it hasn't broken yet) and it allows me to use the coordinates anywhere.
Cheers for your anyway!
Hamish