Programmatically geocode locations

I would like my cesium component to do a location search programmatically. Is there any way of doing that?

The one way I tried doing is injecting the search string to the Geocoder object directly, and then calling the search function in the view model, but the text doesn't appear in my geocoded nor does the searching happen:

    var geocoder = viewer.geocoder;
    geocoder.searchText = "Seattle, CA";;

I had only found one mentioning regarding custom queries but that was more towards having a callback to override the Geocode widget's search function:!topic/cesium-dev/Pr2vv87299I


See the geocode() function here:

Decoupling the geocoder from the UI is also on the roadmap, see #1262.


Thanks for the response Patrick.

I am able to set the searchText but when invoking the geocode function but I am having some trouble determine on which object the geocode function is defined, I tried both of the following:

viewer.geocoder.viewModel.geocode is not a function
viewer.geocoder.geocode is not a function

Also, the Geocoder documentation has no mention of a geocode function for GeocoderViewModel, just a search command.

Am I reading the code wrong? Any more pointers would be most appreciated!