Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.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
Javascript 在html页面中显示用户地理位置_Javascript_Html_Cordova_Geolocation - Fatal编程技术网

Javascript 在html页面中显示用户地理位置

Javascript 在html页面中显示用户地理位置,javascript,html,cordova,geolocation,Javascript,Html,Cordova,Geolocation,我是html5新手,使用cordova,代码如下。一旦我使用html5地理位置对象,我需要在用户当前屏幕中显示该值 function onDeviceReady() { // Get the most accurate position updates available on the // device. var options = { enableHighAccuracy: true }; wat

我是html5新手,使用cordova,代码如下。一旦我使用html5地理位置对象,我需要在用户当前屏幕中显示该值

function onDeviceReady() {
            // Get the most accurate position updates available on the
            // device.
            var options = { enableHighAccuracy: true };
            watchID = navigator.geolocation.watchPosition(onSuccess, onError, options);
        }
        // onSuccess Geolocation       
        function onSuccess(position) {
            var element = document.getElementById('geolocation');
            element.innerHTML = 'Latitude: ' + position.coords.latitude + '<br />' +
                            'Longitude: ' + position.coords.longitude + '<br />' +
                            '<hr />' + element.innerHTML;



}

                            document.write=(element);

<body class="sapUiBody" role="application">
    <p id="geolocation"need to display user geo location here </p>



</body>
函数ondevicerady(){
//在上获取最准确的位置更新
//装置。
var options={enableHighAccurance:true};
watchID=navigator.geolocation.watchPosition(onSuccess、onError、options);
}
//成功地理定位
成功时的功能(位置){
var element=document.getElementById('geolocation');
element.innerHTML='Latitude:'+position.coords.Latitude+'
'+ '经度:'+position.coords.Longitude+'
'+ “
”+element.innerHTML; } document.write=(元素); HTML代码:

<p id="geolocation">your coordinates:</p>

您的坐标:

JavaScript代码:

var x = document.getElementById("geolocation");
if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
} else { 
    x.innerHTML = "Geolocation is not supported by this browser.";
}

function showPosition(position) {
    x.innerHTML+="<br>Latitude: " + position.coords.latitude + 
    "<br>Longitude: " + position.coords.longitude;  
}
var x=document.getElementById(“地理位置”);
if(导航器.地理位置){
navigator.geolocation.getCurrentPosition(showPosition);
}否则{
x、 innerHTML=“此浏览器不支持地理位置。”;
}
功能显示位置(位置){
x、 innerHTML+=“
纬度:”+position.coords.Latitude+ “
经度:”+position.coords.Longitude; }
而您的代码不起作用?das onError向您提供了什么?我的代码正在运行,但我想在屏幕上显示从设备上收集的上述代码的值,类似于printf/document.write(纬度,lungitude)