使用 apache cordova 3 安卓平台
在 geoBroker.java 文件中的 execute 方法中,在 locationManager 实例化后添加以下操作。
if(action.equals("isGPSEnabled")){
PluginResult result;
if ( locationManager.isProviderEnabled( LocationManager.GPS_PROVIDER )){
result = new PluginResult(PluginResult.Status.OK);
}else{
result = new PluginResult(PluginResult.Status.ERROR);
}
callbackContext.sendPluginResult(result);
}
然后在资产的 plugins 文件夹中的 geolocation.js 文件中添加公开新功能
/**
* Asynchronously checks if gps is enabled.
*
* @param {Function} successCallback The function to call when gps is enabled.
* @param {Function} errorCallback The function to call when gps is not enabled. (OPTIONAL)
*/
isGPSEnabled:function(successCallback, errorCallback){
exec(successCallback, errorCallback, "Geolocation", "isGPSEnabled", []);
}
希望能帮助到你