Javascript 如何从自定义dojo模块获取值?

Javascript 如何从自定义dojo模块获取值?,javascript,dojo,Javascript,Dojo,我正在编写一个应用程序的模块化过程。这适用于空间位置 我使用一个事件来查询用户的lat/lon位置,以便在应用程序中使用。下面是我的呼叫片段(单击按钮启动) })) 欢迎任何帮助。我可以通过引用返回更改文档上的文本/html值,但不能将内容作为变量返回 define(['dojo/_base/declare','dojo/_base/lang','dojo/dom', 'esri/geometry/Point','esri/SpatialReference'], function ( d

我正在编写一个应用程序的模块化过程。这适用于空间位置

我使用一个事件来查询用户的lat/lon位置,以便在应用程序中使用。下面是我的呼叫片段(单击按钮启动)

}))

欢迎任何帮助。我可以通过引用返回更改文档上的文本/html值,但不能将内容作为变量返回

define(['dojo/_base/declare','dojo/_base/lang','dojo/dom',
'esri/geometry/Point','esri/SpatialReference'], function (
    declare, lang, dom, Point, SpatialReference) {
return {
    findUserLocPT: function (spatialRef) {
        var geom;
        var location_timeout = setTimeout("geolocFail()", 5000);
        navigator.geolocation.getCurrentPosition(function (position) {
            clearTimeout(location_timeout);

            var lat = position.coords.latitude;
            var lon = position.coords.longitude;

            setTimeout(function () {
                geom = new Point(lon, lat, spatialRef);
                //console.log writes out the geom but that isnt what I am after
                console.log(geom);
                //I want to return this value
                return geom;
            }, 500);
        });
        function geolocFail() {
            console.log("GeoLocation Failure");
        }
    }
}//end of the return

安迪

好的,我不知道这是否是最好的答案,但我现在有一个

我在“test.html”页面中添加了一个全局变量

 <script>
    var theGeom;  //This is the variable
    require([
        'dojo/dom',
我不确定这是不是最好的办法。如果你有更好的,请告诉我

安迪

 <script>
    var theGeom;  //This is the variable
    require([
        'dojo/dom',
setTimeout(function () {
    geom = new Point(lon, lat, spatialRef);                                     
    theGeom = geom;    //Here is the feedback of the value to the global variable.                 
    return myGeom;
}, 500);


$('#whereAmIButton').click(function () {
    var spatialRef = new esri.SpatialReference({'wkid':4326});              
    testModule.findUserLocPT(spatialRef);               
    setTimeout(function () {
        console.log(theGeom);   //here is the value set and ready to use
            },2000);
});