0
我在我的项目中遇到了一个关键问题。我是Appcelerator中的新成员,我不知道如何解决它。这个错误没有得到我的机器。但是我使用的另一台机器也一样。Uncaught TypeError:Object#<Geolocation> has no method'hasLocationPermissions'
第一个文件
/**
* Hepers for run-time permissions.
*/
// DEPENDENCIES
var dialogs = require('alloy/dialogs');
// PUBLIC INTERFACE
exports.requestLocationPermissions = requestLocationPermissions;
// PRIVATE FUNCTIONS
function requestLocationPermissions(authorizationType, callback) {
// FIXME: Always returns false on Android 6
// https://jira.appcelerator.org/browse/TIMOB-23135
if (OS_IOS && !Ti.Geolocation.locationServicesEnabled) {
return callback({
success : false,
error : 'Location Services Disabled'
});
}
// Permissions already granted
if (Ti.Geolocation.hasLocationPermissions(authorizationType)) {
return callback({
success : true
});
}
// On iOS we can determine why we do not have permission
if (OS_IOS) {
if (Ti.Geolocation.locationServicesAuthorization === Ti.Geolocation.AUTHORIZATION_RESTRICTED) {
return callback({
success : false,
error : 'Your device policy does not allow Geolocation'
});
} else if (Ti.Geolocation.locationServicesAuthorization === Ti.Geolocation.AUTHORIZATION_DENIED) {
dialogs.confirm({
title : 'You denied permission before',
message : 'Tap Yes to open the Settings app to restore permissions, then try again.',
callback : function() {
Ti.Platform.openURL(Ti.App.iOS.applicationOpenSettingsURL);
}
});
// return success:false without an error since we've informed the user already
return callback({
success : false
});
}
}
// Request permission
Ti.Geolocation.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE, function(e) {
if (!e.success) {
return callback({
success : false,
error : e.error || 'Failed to request Location Permissions'
});
} else {
callback({
success : true
});
}
});
}
第二个文件(我将首先(文件名:。Permi)在这里
var Perm = require('Permi');
$.window.addEventListener("focus", function(e) {
Perm.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE, function(e) {
if (!e.success) {
if (e.error) {
}
return;
} else {
Titanium.Geolocation.getCurrentPosition(function(e) {
if (e.success == false) {
} else {
longitude = e.coords.longitude;
latitude = e.coords.latitude;
Titanium.Geolocation.reverseGeocoder(latitude, longitude, function(e) {
if (e.success) {
var places = e.places;
if (places && places.length) {
driverCity = places[0].city;
driverState = places[0].address;
annotation.title = e.places[0].displayAddress;
} else {
}
}
});
$.mapview.applyProperties({
mapType : Alloy.Globals.Map.NORMAL_TYPE,
region : {
latitude : latitude,
longitude : longitude,
latitudeDelta : 0.05,
longitudeDelta : 0.05,
},
animate : true,
regionFit : true,
userLocation : false,
});
var annotation = Alloy.Globals.Map.createAnnotation({
latitude : latitude,
longitude : longitude,
title : "The DEMO",
pincolor : Alloy.Globals.Map.ANNOTATION_RED,
myid : 1
});
$.mapview.addAnnotation(annotation);
}
});
}
});
this.removeEventListener('focus', arg);
});
任何帮助将十分赞赏感谢
问题发生在哪个系统上? 错误信息是什么? –
您使用的是什么Titanium SDK版本? – developer82
问题与Mac。我正在使用Titanium SDK 5.2.2 GA – Dev786