简体   繁体   English

地理位置不起作用-如何解决?

[英]Geolocation does not work - how to fix that?

Please do not mark it as a duplicate question, because the various situations I have seen and dozens of suggestions have failed in my case. 请不要将其标记为重复的问题,因为我所遇到的各种情况和许多建议在我的案例中都失败了。 Which is very tiring and frustrating. 这是非常累人和令人沮丧的。

I have an application made in Ionic that needs to use Geolocation. 我有一个使用Ionic制作的应用程序,需要使用Geolocation。 I followed the ionic documentation and it works great in the browser. 我遵循了离子文件,它在浏览器中很好用。 But on Android, not! 但是在Android上,不是! Which is ridiculous from my point of view, since such a basic feature does not work on such a widespread framework as Ionic. 从我的角度来看,这是荒谬的,因为这样的基本功能不适用于像Ionic这样的广泛框架。 Leaving aside the complaint, this is my code: 撇开投诉,这是我的代码:

  getLocation() {
    return new Promise((resolve, reject) => {
      var options = {
        enableHighAccuracy: true,
        maximumAge: 0
      };

      this.geolocation.getCurrentPosition(options).then((resp) => {
        resolve(resp.coords);
       }).catch(() => {
         resolve(undefined);
       });
    });
  }

The problem is that the above routine does not return nor in THEN much less in CATCH when I install the application on Android, which is exactly the same complaint from many other developers. 问题是,当我在Android上安装应用程序时,上述例程不会返回,也不会在CATCH中返回,这与许多其他开发人员的抱怨完全相同。 However, as I mentioned, the various tips did not work. 但是,正如我提到的,各种技巧都行不通。

Can someone help me solve this cause? 有人可以帮我解决这个问题吗? Or even suggest another way? 甚至建议另一种方式? I have already tried navigator, pure javascript, etc. In all this I was not able to resolve this problem. 我已经尝试过导航器,纯JavaScript等。在所有这些方面,我都无法解决此问题。

Try adding timeout to the GeolocationOptions . 尝试将timeout添加到GeolocationOptions

let options = { 
    enableHighAccuracy: true,
    timeout: 20000 
  };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM