当前GPS以orbeon形式坐标

时间:2015-09-19 09:39:58

标签: orbeon xforms

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

我不太了解xforms,所以任何人都不知道如何用JavaScript获得orbeon形式的当前GPS坐标?

2 个答案:

答案 0 :(得分:1)

试试这段代码:              GPS演示         

        <!-- 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>

答案 1 :(得分:0)

我认为您指的是使用HTML5地理定位API来获取用户的当前位置,并使用该值来设置字段的值。对于第一部分,您可以查看this article on the geolocation API。获得位置后,您可以使用ORBEON.xforms.Document.setValue()设置字段的值。有关详情,请参阅documentation on setting values from JavaScript