javascript 如何使用离线设备捕获地理位置 - 科尔多瓦

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30713808/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 12:35:19  来源:igfitidea点击:

how capturing geolocation with device offline - cordova

javascriptandroidcordovageolocation

提问by Crazy

I am developing an application using the cordova and found a need to take the data of latitude and longitude of the User, but my application will be used offline (without internet access).

我正在使用cordova开发一个应用程序,发现需要获取用户的经纬度数据,但我的应用程序将离线使用(没有互联网访问)。

I'm with two questions:

我有两个问题:

1 - How to check if the unit is active GPS or not?

1 - 如何检查设备是否启用 GPS?

2 - How I can get the latitude and longitude Offline without internet connection? It's possible?

2 - 如何在没有互联网连接的情况下离线获取纬度和经度?这是可能的?

采纳答案by Alejandro Teixeira Mu?oz

I′ll try to answer you:

我会尽力回答你:

1.- There you have the way to use PhoneGap GeoLication APIto check location, and if GPS is enabled. Check this too: Use PhoneGap to Check if GPS is enabled

1.- 您可以使用PhoneGap GeoLication API来检查位置,以及是否启用了 GPS。也检查一下: 使用PhoneGap检查是否启用了GPS

2.- Yes, the GPS is a satellite system that allows your device to track it′s current position on earth. It′s independent from your Cellphone operator, and then, from the Internet Connection. Then, your device will be able to know it′s position. HTML5 offline mode and geolocation

2.- 是的,GPS 是一个卫星系统,允许您的设备跟踪它在地球上的当前位置。它独立于您的手机运营商,然后独立于互联网连接。然后,您的设备将能够知道它的位置。HTML5 离线模式和地理定位

In addition, you′ll probably need Internet connection to show a map. There are not much solutions for offline maps. Just artisan ones: http://davidrs.com/wp/phonegap-3-0-leaflet-offline-maps/

此外,您可能需要 Internet 连接才能显示地图。离线地图的解决方案并不多。只是工匠的:http: //davidrs.com/wp/phonegap-3-0-leaflet-offline-maps/

Hope it helps

希望能帮助到你

REMEMBER: When turning on plane mode, most of devices will turn off GPS antenna too.

记住:打开飞机模式时,大多数设备也会关闭 GPS 天线。

回答by DaveAlden

To check if the GPS is available or not you can use this diagnostic plugin- it works for Android and iOS. It can also be used to display the native location settings screen to allow the user to enable location services. For example:

要检查 GPS 是否可用,您可以使用此诊断插件- 它适用于 Android 和 iOS。它还可用于显示本地位置设置屏幕,以允许用户启用位置服务。例如:

cordova.plugins.diagnostic.isLocationEnabled(function(enabled){
    console.log("GPS is "+(enabled ? "enabled" : "disabled");
    if(!enabled){
        cordova.plugins.diagnostic.switchToLocationSettings();
    }
},function(error){
    console.error("An error occurred: "+ error);
});

As the other answer already states, you can receive a user's location using GPS without needing an internet connection using the geolocation API, but if you want to display a map you'll need a custom solution that doesn't rely on online maps such as Google.

正如另一个答案已经指出的那样,您可以使用 GPS 接收用户的位置,而无需使用地理定位 API 的互联网连接,但是如果您想显示地图,您将需要一个不依赖在线地图的自定义解决方案,例如谷歌。

If you want to record the user's location while offline, you can store this information offline in local persistent storage and upload it when the user has an internet connection again. You could use something like lawnchairfor the storage.

如果您想在离线时记录用户的位置,您可以将此信息离线存储在本地持久存储中,并在用户再次连接互联网时上传。您可以使用诸如草坪椅之类的东西来存放物品。