# Programmatically geocode locations

**URL:** <https://community.cesium.com/t/programmatically-geocode-locations/3519>\
**Category:** CesiumJS\
**Created:** [January 2, 2016, 1:20am UTC](https://community.cesium.com/t/programmatically-geocode-locations/3519 "2016-01-02T01:20:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zehao.chang](https://avatars.discourse-cdn.com/v4/letter/z/ac91a4/32.png) [@zehao.chang](https://community.cesium.com/u/zehao.chang)\
**Post date:** [January 2, 2016, 1:20am UTC](https://community.cesium.com/t/programmatically-geocode-locations/3519/1 "2016-01-02T01:20:33Z")

</div>

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:

&nbsp;&nbsp;&nbsp;&nbsp;var geocoder = viewer.geocoder;  
&nbsp;&nbsp;&nbsp;&nbsp;geocoder.searchText = "Seattle, CA";  
&nbsp;&nbsp;&nbsp;&nbsp;geocoder.viewModel.search();

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:  
[https://groups.google.com/forum/#!topic/cesium-dev/Pr2vv87299I](https://groups.google.com/forum/#!topic/cesium-dev/Pr2vv87299I)

---

<div class="post-metadata">

**Author:** ![patrick](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/patrick/32/2045_2.png) [@patrick](https://community.cesium.com/u/patrick)\
**Post date:** [January 3, 2016, 9:40pm UTC](https://community.cesium.com/t/programmatically-geocode-locations/3519/2 "2016-01-03T21:40:43Z")

</div>

Hi,

See the geocode() function here: [https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Widgets/Geocoder/GeocoderViewModel.js#L218](https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Widgets/Geocoder/GeocoderViewModel.js#L218)

Decoupling the geocoder from the UI is also on the roadmap, see [#1262](https://github.com/AnalyticalGraphicsInc/cesium/issues/1262).

Patrick

---

<div class="post-metadata">

**Author:** ![zehao.chang](https://avatars.discourse-cdn.com/v4/letter/z/ac91a4/32.png) [@zehao.chang](https://community.cesium.com/u/zehao.chang)\
**Post date:** [January 14, 2016, 10:16pm UTC](https://community.cesium.com/t/programmatically-geocode-locations/3519/3 "2016-01-14T22:16:57Z")

</div>

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.  
[https://cesiumjs.org/Cesium/Build/Documentation/GeocoderViewModel.html](https://cesiumjs.org/Cesium/Build/Documentation/GeocoderViewModel.html)

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