orbeon 形式的当前 GPS 坐标

Current GPS Coordinates in orbeon forms

我正在使用 orbeon 表单 4.8,我想在 orbeon 表单字段中获取当前 GPS 坐标。我尝试 运行 表单内的脚本,但它没有显示任何内容。

我不太了解 xforms,所以谁能知道我如何使用 JavaScript 获取 orbeon 格式的当前 GPS 坐标?

我想您指的是使用 HTML5 地理定位 API 来获取用户的当前位置,并使用该值来设置字段的值。对于第一部分,您可以查看 this article on the geolocation API. Once you have have the location, you can set the value of a field using the ORBEON.xforms.Document.setValue(). For more on this, see the documentation on setting values from JavaScript.

试试这个代码: 全球定位系统演示

        <!-- Main instance -->
        <xf:instance id="fr-form-instance" xxf:exclude-result-prefixes="#all">
            <form>
                <section-1>
                    <control-1/>
                    <foo>42</foo>
                    <bar/>
                </section-1>
            </form>
        </xf:instance>

        <!-- Bindings -->
        <xf:bind id="fr-form-binds" ref="instance('fr-form-instance')">
            <xf:bind id="section-1-bind" name="section-1" ref="section-1">
                <xf:bind id="control-1-bind" name="control-1" ref="control-1"/>
            </xf:bind>
        </xf:bind>

        <!-- Metadata -->
        <xf:instance xxf:readonly="true" id="fr-form-metadata" xxf:exclude-result-prefixes="#all">
            <metadata>
                <application-name>testgps</application-name>
                <form-name>testgps</form-name>
                <title xml:lang="en">Untitled Form</title>
                <description xml:lang="en"/>
                <singleton>false</singleton>
            </metadata>
        </xf:instance>

        <!-- Attachments -->
        <xf:instance id="fr-form-attachments" xxf:exclude-result-prefixes="#all">
            <attachments>
                <css mediatype="text/css" filename="" size=""/>
                <pdf mediatype="application/pdf" filename="" size=""/>
            </attachments>
        </xf:instance>

        <!-- All form resources -->
        <!-- Don't make readonly by default in case a service modifies the resources -->
        <xf:instance id="fr-form-resources" xxf:readonly="false" xxf:exclude-result-prefixes="#all">
            <resources>
                <resource xml:lang="en">
                    <section-1>
                        <label>Untitled Section</label>
                    </section-1>
                    <control-1>
                        <label/>
                        <hint/>
                        <alert/>
                    </control-1>
                </resource>
            </resources>
        </xf:instance>

        <!-- Utility instances for services -->
        <xf:instance id="fr-service-request-instance" xxf:exclude-result-prefixes="#all">
            <request/>
        </xf:instance>

        <xf:instance id="fr-service-response-instance" xxf:exclude-result-prefixes="#all">
            <response/>
        </xf:instance>

    </xf:model>
</xh:head>
<xh:body>
    <fr:view>
        <fr:body xmlns:oxf="http://www.orbeon.com/oxf/processors"
                 xmlns:p="http://www.orbeon.com/oxf/pipeline"
                 xmlns:xbl="http://www.w3.org/ns/xbl">
            <fr:section id="section-1-control" bind="section-1-bind">
                <xf:label ref="$form-resources/section-1/label"/>
                <fr:grid>
                    <xh:tr>
                        <xh:td>
                            <xf:input id="control-1-control" bind="control-1-bind">
                                <xf:label ref="$form-resources/control-1/label"/>
                                <xf:hint ref="$form-resources/control-1/hint"/>
                                <xf:alert ref="$fr-resources/detail/labels/alert"/>
                            </xf:input>
                            <xf:input ref="foo" id="foo">
                                               <xf:label class="fixed-width">Value of foo:</xf:label>
                                                 </xf:input>
                                              <xf:output ref="bar">
                                         <xf:label class="fixed-width">Value of bar:</xf:label>
                                           </xf:output>
                                        <xf:trigger>
                                            <xf:label>JavaScript</xf:label>
                                               <xxf:script ev:event="DOMActivate">
                        var mycontrol = ORBEON.jQuery('*[id $= "control-1-control"]');
                    var value = ORBEON.xforms.Document.getValue(mycontrol.attr('id'));
                       navigator.geolocation.getCurrentPosition(showPosition);
                            function showPosition(position){
                                                   var lat=position.coords.latitude;
                                                  var long=position.coords.longitude;
                                                   var longlat=lat+","+long;
                                        ORBEON.xforms.Document.setValue(mycontrol.attr('id'),longlat);           
                                                   }           


</xxf:script>
                            </xf:trigger>
                        </xh:td>
                        <xh:td/>
                        <xh:td/>
                        <xh:td/>
                    </xh:tr>
                </fr:grid>
            </fr:section>
        </fr:body>
    </fr:view>
</xh:body>