如何获取当前位置在phonegap? [英] how to get current location in phonegap?

查看:120
本文介绍了如何获取当前位置在phonegap?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中添加Geolocation插件,并使用此代码在phonegap中获取当前位置。但此代码无效。

  document.addEventListener(deviceready,onDeviceReady,false); 

function onDeviceReady(){
alert(4);
navigator.geolocation.getCurrentPosition(onSuccess,onError);
}

function onSuccess(position){
alert(1);
}

function onError(error){
alert(3);
}

我的代码中的问题在哪里?


>检查地理位置是否正确安装


  • 重新启动手机(愚蠢的解决方案, >

  • 检查您的地理位置权限在设备中打开设置


  • 使用此代码测试



    选项= {enableHighAccuracy:true};
    navigator.geolocation.getCurrentPosition(onSuccess,onError,options);


  • 使用eclipse logcat获取错误。



  • i add Geolocation plugin in my app and use this code for get current location in phonegap. but this code dose not work.

        document.addEventListener("deviceready", onDeviceReady, false);
    
    function onDeviceReady() {
        alert("4");
        navigator.geolocation.getCurrentPosition(onSuccess, onError);
    }
    
    function onSuccess(position) {
        alert("1");
    }
    
    function onError(error) {
        alert("3");
    }
    

    Where is the problem in my code?

    thank you and sorry for my poor english.

    解决方案

    1. check if geolocation is properly installed or not

    2. restart your phone (silly solution but it works sometimes.I faced it once)

    3. check if your geo permissions & settings are turned on in device

    4. test with this code

      options = { enableHighAccuracy: true }; navigator.geolocation.getCurrentPosition(onSuccess, onError, options);

    5. If you're using android, try to get the error with eclipse logcat.

    这篇关于如何获取当前位置在phonegap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆