地理定位在智能手机上不起作用
Geolocation does not work on smartphone
我想在我的应用程序中实现地理定位。
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(getPosition, errorGettingPosition);
}
function getPosition(position) {
var myLatitude = position.coords.latitude;
var myLongitude = position.coords.longitude;
var radiusEarth = 6371;
myLongitude = myLongitude * (Math.PI / 180);
myLatitude = myLatitude * (Math.PI / 180);
var x0 = myLongitude * radiusEarth * Math.cos(myLatitude);
var y0 = myLatitude * radiusEarth;
for (var i = 0; i < list.length; i++) {
var vendorLongitude = list[i].Longitude = list[i].Longitude * (Math.PI / 180);
var vendorLatitude = list[i].Latitude = list[i].Latitude * (Math.PI / 180);
var x1 = vendorLongitude * radiusEarth * Math.cos(vendorLatitude);
var y1 = vendorLatitude * radiusEarth;
var dx = x0 - x1;
var dy = y0 - y1;
var d = Math.sqrt((dx * dx) + (dy * dy));
if (d < 1) {
list[i].Distance = Math.round(d * 1000) + " m";
} else {
list[i].Distance = Math.round(d * 10) / 10 + " km";
}
}
//add vendors to scope
$scope.vendors = list;
}
function errorGettingPosition(err) {
if (err.code == 1) {
alert("User denied geolocation.");
}
else if (err.code == 2) {
alert("Position unavailable.");
}
else if (err.code == 3) {
alert("Timeout expired.");
}
else {
alert("ERROR:" + err.message);
}
}
这些代码行是我写的。在电脑上的浏览器中,它会完美地工作,但如果我在智能手机(Android,5.1.1版)上安装这个应用程序,它就不工作了,我不知道为什么。它也不会进入智能手机上的错误功能。
你知道该怎么办吗?
这个可以进入错误函数
function initiate_watchlocation() {
if (watchProcess == null) {
watchProcess = navigator.geolocation.watchPosition(onSuccess, onError);
}
}
var onSuccess = function(position) {
var myLatitude = position.coords.latitude;
var myLongitude = position.coords.longitude;
};
function onError(error) {
alert_box('code: ' + error.code + ''n' +
'message: ' + error.message + ''n');
}
考虑在document.ready.中运行它
它非常特别。当应用程序加载网站时,它会从getCurrentPosition()函数开始。然后我可以走过去,什么都没发生。但几秒钟后(大约5秒钟),它将通过成功回调。我将结果保存在$scope中,因为我使用AngularJS。但在GUI中,我无法识别任何关于经度和纬度的位置。
相关文章:
- 手机摄像头没有'不起作用
- HTML 视频标签在野生动物园和手机上不起作用
- 角度智能表不起作用
- 为什么jQuery效果在我的手机上不起作用,但在我的桌面上工作
- JSON.stringify在黑莓手机中不起作用
- 手机的基本jquery切换菜单不起作用
- 本地存储在Windows手机PhoneGap应用程序中不起作用
- 为什么YouTube嵌入的代码在三星这样的智能手机上不起作用
- regex手机验证不起作用-javascript
- bootstrap折叠导航在我的wordpress主题手机中不起作用
- Cocos2D JS花栗鼠PhysicsSprite移动操作在Android手机中不起作用
- 在Angular 1.5.8版本的智能表中,行选择不起作用
- 拖放在触摸屏手机上不起作用
- 当应用bootstrap时,选择下拉菜单在手机和ipad视图中不起作用
- Javascript绝对路径智能感知在VS 2012中不起作用
- 地理定位在智能手机上不起作用
- 切换菜单在智能手机上不起作用
- ng点击在手机屏幕上不起作用
- 删除键在日期项(智能 GWT)中不起作用
- 智能表排序不起作用