Jelajahi Sumber

获取位置错误处理

gcz 3 tahun lalu
induk
melakukan
9eb5a15db1
1 mengubah file dengan 20 tambahan dan 1 penghapusan
  1. 20 1
      pages/index/index.vue

+ 20 - 1
pages/index/index.vue

@@ -229,7 +229,26 @@
 						that.latitude = pos.coords.latitude;
 						that.longitude = pos.coords.longitude;
 						that.getCityNameByLonLat(that.latLongItude)
-					})
+					},function(err){
+                    // 错误处理
+                    switch(err.code) {
+                        case 1: 
+                            alert("位置服务被拒绝。");
+                        break;
+
+                        case 2: 
+                            alert("暂时获取不到位置信息。");
+                        break;
+
+                        case 3:
+                            alert("获取信息超时。");
+                        break;
+
+                        default:
+                            alert("未知错误。");
+                        break;
+                    }
+                })
 				}else{
 					console.log("当前系统不支持GPS API")
 				};