Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html ons.navigator.pushPage不使用PhoneGap地理位置_Html_Angularjs_Cordova_Onsen Ui - Fatal编程技术网

Html ons.navigator.pushPage不使用PhoneGap地理位置

Html ons.navigator.pushPage不使用PhoneGap地理位置,html,angularjs,cordova,onsen-ui,Html,Angularjs,Cordova,Onsen Ui,当我使用ons.navigator.pushPage并导航到附近的html页面时,它应该会显示当前的地理位置坐标。然而,它并没有做到这一点。当我直接加载SearchNearest页面时,它完美地显示了坐标。你知道吗 index.html searchnear/index.html 您的JS不会在searchnear/index.html上被激发,因为您的页面正在异步加载 我建议在页面完全加载时设置某种回调,以便您可以执行getCurrentPosition方法 或者,您可以事先获得位置,然后将s

当我使用ons.navigator.pushPage并导航到附近的html页面时,它应该会显示当前的地理位置坐标。然而,它并没有做到这一点。当我直接加载SearchNearest页面时,它完美地显示了坐标。你知道吗

index.html

searchnear/index.html


您的JS不会在searchnear/index.html上被激发,因为您的页面正在异步加载

我建议在页面完全加载时设置某种回调,以便您可以执行getCurrentPosition方法

或者,您可以事先获得位置,然后将success对象传递到searchnearly页面

<body ng-controller="courseController">

<ons-navigator title="Class Finder">
<ons-page>
<ons-row>
    <ons-col size="80" style="padding: 8px">
    <ons-search-input ng-model="searchText" placeholder="Search..." >
    </ons-search-input>
    </ons-col>
    <ons-col size="20" >
    <ons-button type="large--quiet" ng-click="ons.navigator.pushPage('searchNearby/index.html',{title:'Search Nearby'})">Search nearby
    </ons-button>
    </ons-col>
</ons-row>
</ons-page>
</ons-navigator>
</body>
<body>
<p id="geolocation">Finding geolocation...</p>
<div id="t01"> </div>
    <script type="text/javascript" charset="utf-8">
    var lat,lon;
    document.addEventListener("deviceready", onDeviceReady, false);
    function onDeviceReady() {
    navigator.geolocation.getCurrentPosition(onSuccess, onError);
    }
    function onSuccess(position) {

    var element = document.getElementById('geolocation');

    element.innerHTML = 'Latitude: '           + position.coords.latitude + '<br />' +
                        'Longitude: '          + position.coords.longitude  + '<br />' +
                        'Altitude: '           + position.coords.altitude              + '<br />' +
                        'Accuracy: '           + position.coords.accuracy              + '<br />' +
                        'Altitude Accuracy: '  + position.coords.altitudeAccuracy      + '<br />' +
                        'Heading: '            + position.coords.heading               + '<br />' +
                        'Speed: '              + position.coords.speed                 + '<br />' +
                        'Timestamp: '          + position.timestamp                    + '<br />';

}
function onError(error){
        alert('code: '    + error.code    + '\n' +
              'message: ' + error.message + '\n');
}
</script>   
</body>