简体   繁体   English

如何使用离线设备捕获地理位置 -cordova

[英]how capturing geolocation with device offline - cordova

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? 2 - 如何在没有互联网连接的情况下离线获取纬度和经度? It's possible?这是可能的?

I´ll try to answer you:我会尽力回答你:

1.- There you have the way to use PhoneGap GeoLication API to check location, and if GPS is enabled. 1.- 您可以使用PhoneGap GeoLication API来检查位置,以及是否启用了 GPS。 Check this too: Use PhoneGap to Check if GPS is enabled也检查一下: 使用PhoneGap检查是否启用了GPS

2.- Yes, the GPS is a satellite system that allows your device to track it´s current position on earth. 2.- 是的,GPS 是一种卫星系统,可让您的设备跟踪它在地球上的当前位置。 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 HTML5 离线模式和地理位置

In addition, you´ll probably need Internet connection to show a map.此外,您可能需要 Internet 连接才能显示地图。 There are not much solutions for offline maps.离线地图的解决方案并不多。 Just artisan ones: http://davidrs.com/wp/phonegap-3-0-leaflet-offline-maps/只是工匠的: 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 天线。

To check if the GPS is available or not you can use this diagnostic plugin - it works for Android and iOS.要检查 GPS 是否可用,您可以使用此诊断插件- 它适用于 Android 和 iOS。 It can also be used to display the native location settings screen to allow the user to enable location services.它还可用于显示本地位置设置屏幕,以允许用户启用位置服务。 For example:例如:

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 lawnchair for the storage.您可以使用诸如草坪椅之类的东西来存放物品。

You can use geolocationOptions to controll if it use the hardware gps module:您可以使用 geolocationOptions 来控制它是否使用硬件 gps 模块:

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

then when your phone is gps ready, you can get gps info without network access.然后当您的手机准备好 gps 时,您可以在没有网络访问的情况下获取 gps 信息。

enableHighAccuracy: Provides a hint that the application needs the best possible results. enableHighAccuracy:提供应用程序需要最佳可能结果的提示。 By default, the device attempts to retrieve a Position using network-based methods.默认情况下,设备尝试使用基于网络的方法检索位置。 Setting this property to true tells the framework to use more accurate methods, such as satellite positioning.将此属性设置为 true 会告诉框架使用更准确的方法,例如卫星定位。 (Boolean) (布尔值)

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

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