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