@heycar/heycars-map 0.9.20-timeout4 → 0.9.21-alpha2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -19,7 +19,7 @@ if (typeof GeolocationPositionError === "undefined") {
19
19
  };
20
20
  }
21
21
  const name = "@heycar/heycars-map";
22
- const version = "0.9.20-timeout4";
22
+ const version = "0.9.21-alpha2";
23
23
  const type = "module";
24
24
  const bin = {
25
25
  checkVersion: "./bin/checkVersion.js"
@@ -4554,7 +4554,8 @@ function wechatWatchPosition(onSuccess, onError, option) {
4554
4554
  const { timeout } = option;
4555
4555
  let enable = true;
4556
4556
  let prevGeoPosition = void 0;
4557
- const isGeoWorkingRef = Vue.ref(true);
4557
+ let lastSuccessfulResponse = void 0;
4558
+ let geoErrorMessage = void 0;
4558
4559
  const { visibilityStateRef, unwatchVisibilityState } = watchVisibilityState();
4559
4560
  const startWatch = async () => {
4560
4561
  try {
@@ -4583,26 +4584,24 @@ function wechatWatchPosition(onSuccess, onError, option) {
4583
4584
  if (isHandled)
4584
4585
  return;
4585
4586
  isHandled = true;
4586
- isGeoWorkingRef.value = true;
4587
+ lastSuccessfulResponse = res;
4588
+ geoErrorMessage = void 0;
4587
4589
  resolve(wxGetLocationSuccessResponse2GeolocationPosition(res));
4588
4590
  },
4589
4591
  fail(res) {
4590
4592
  if (isHandled)
4591
4593
  return;
4592
4594
  isHandled = true;
4593
- const isGeoWorking = isGeoWorkingRef.value;
4594
- isGeoWorkingRef.value = false;
4595
- console.warn(
4596
- "MyWarning: wx.getLocation failed errcode, errmsg = ",
4597
- res.errCode,
4598
- res.errMsg
4599
- );
4595
+ const { errMsg: message, errCode: code } = res;
4596
+ const prevMessage = geoErrorMessage;
4597
+ geoErrorMessage = message;
4600
4598
  resolve(void 0);
4601
- if (!isGeoWorking)
4599
+ if (prevMessage === message)
4602
4600
  return;
4601
+ console.warn("MyWarning: wx.getLocation failed code, message = ", code, message);
4603
4602
  onError == null ? void 0 : onError(
4604
4603
  createCustomGeolocationPositionError(
4605
- res.errMsg,
4604
+ message,
4606
4605
  GeolocationPositionError.PERMISSION_DENIED
4607
4606
  )
4608
4607
  );
@@ -4613,12 +4612,21 @@ function wechatWatchPosition(onSuccess, onError, option) {
4613
4612
  setTimeout(() => {
4614
4613
  if (isHandled)
4615
4614
  return;
4615
+ if (lastSuccessfulResponse) {
4616
+ console.warn("警告: my.getLocation failed with errcode 13 which has been bypassed");
4617
+ return resolve(
4618
+ wxGetLocationSuccessResponse2GeolocationPosition(lastSuccessfulResponse)
4619
+ );
4620
+ }
4621
+ const message = `Custom Timeout: exceed ${timeout}s`;
4622
+ const prevMessage = geoErrorMessage;
4623
+ geoErrorMessage = message;
4616
4624
  resolve(void 0);
4625
+ if (prevMessage === message)
4626
+ return;
4627
+ console.warn("MyWarning: wx.getLocation 触发自定义超时, message = ", message);
4617
4628
  onError == null ? void 0 : onError(
4618
- createCustomGeolocationPositionError(
4619
- `Custom Timeout: exceed ${timeout}s`,
4620
- GeolocationPositionError.TIMEOUT
4621
- )
4629
+ createCustomGeolocationPositionError(message, GeolocationPositionError.TIMEOUT)
4622
4630
  );
4623
4631
  }, timeout);
4624
4632
  });
@@ -4637,9 +4645,9 @@ function wechatWatchPosition(onSuccess, onError, option) {
4637
4645
  function alipayWatchPosition(onSuccess, onError, option, getLocationFn) {
4638
4646
  let enable = true;
4639
4647
  let prevGeoPosition = void 0;
4648
+ let lastSuccessfulResponse = void 0;
4649
+ let geoErrorMessage = void 0;
4640
4650
  const { timeout = ALIPAY_GEO_CACHE_TIMEOUT } = option;
4641
- const isGeoWorkingRef = Vue.ref(true);
4642
- const lastSuccessfulResponseRef = Vue.ref();
4643
4651
  const { visibilityStateRef, unwatchVisibilityState } = watchVisibilityState();
4644
4652
  const startWatch = async () => {
4645
4653
  do {
@@ -4649,8 +4657,8 @@ function alipayWatchPosition(onSuccess, onError, option, getLocationFn) {
4649
4657
  }
4650
4658
  const geoPosition = await new Promise((resolve) => {
4651
4659
  const handleSuccess = (res) => {
4652
- lastSuccessfulResponseRef.value = res;
4653
- isGeoWorkingRef.value = true;
4660
+ lastSuccessfulResponse = res;
4661
+ geoErrorMessage = void 0;
4654
4662
  resolve(alipayMyGetLocationSuccessResponse2GeolocationPosition(res));
4655
4663
  };
4656
4664
  getLocationFn({
@@ -4658,25 +4666,21 @@ function alipayWatchPosition(onSuccess, onError, option, getLocationFn) {
4658
4666
  cacheTimeout: timeout / 1e3,
4659
4667
  success: handleSuccess,
4660
4668
  fail(res) {
4661
- if (res.error === 13 && lastSuccessfulResponseRef.value) {
4662
- console.warn(
4663
- "MyWarning: my.getLocation failed with errcode 13 which has been bypassed"
4669
+ if (res.error === 13 && lastSuccessfulResponse) {
4670
+ console.warn("警告: my.getLocation failed with errcode 13 which has been bypassed");
4671
+ return resolve(
4672
+ alipayMyGetLocationSuccessResponse2GeolocationPosition(lastSuccessfulResponse)
4664
4673
  );
4665
- return handleSuccess(lastSuccessfulResponseRef.value);
4666
4674
  }
4667
- const isGeoWorking = isGeoWorkingRef.value;
4668
- isGeoWorkingRef.value = false;
4675
+ const { errorMessage: message, error: code } = res;
4676
+ const prevMessage = geoErrorMessage;
4677
+ geoErrorMessage = message;
4669
4678
  resolve(void 0);
4670
- if (!isGeoWorking)
4679
+ if (prevMessage === message)
4671
4680
  return;
4672
- const { error, errorMessage } = res;
4673
- console.warn(
4674
- "MyWarning: my.getLocation failed errcode, errmsg = ",
4675
- error,
4676
- errorMessage
4677
- );
4678
- const geoErrorCode = alipayMyGetLocationError2GeolocationPositionErrorCode(error);
4679
- onError == null ? void 0 : onError(createCustomGeolocationPositionError(errorMessage, geoErrorCode));
4681
+ console.warn("MyWarning: my.getLocation failed code, message = ", code, message);
4682
+ const geoErrorCode = alipayMyGetLocationError2GeolocationPositionErrorCode(code);
4683
+ onError == null ? void 0 : onError(createCustomGeolocationPositionError(message, geoErrorCode));
4680
4684
  }
4681
4685
  });
4682
4686
  });
@@ -4699,7 +4703,7 @@ const apGetLocation = ({ type: type2, cacheTimeout, success, fail }) => {
4699
4703
  function androidWatchPosition(onSuccess, onError, option) {
4700
4704
  let enable = true;
4701
4705
  let prevGeoPosition = void 0;
4702
- const isGeoWorkingRef = Vue.ref(true);
4706
+ let geoErrorMessage = void 0;
4703
4707
  const { visibilityStateRef, unwatchVisibilityState } = watchVisibilityState();
4704
4708
  const startWatch = async () => {
4705
4709
  do {
@@ -4708,21 +4712,26 @@ function androidWatchPosition(onSuccess, onError, option) {
4708
4712
  continue;
4709
4713
  }
4710
4714
  const geoPosition = await new Promise((resolve) => {
4711
- navigator.geolocation.getCurrentPosition(
4715
+ const watchId = navigator.geolocation.watchPosition(
4712
4716
  function onSuccess2(geoLocationPosition) {
4713
- isGeoWorkingRef.value = true;
4717
+ navigator.geolocation.clearWatch(watchId);
4718
+ geoErrorMessage = void 0;
4714
4719
  resolve(geoLocationPosition);
4715
4720
  },
4716
4721
  function onFail(geoError) {
4717
- const isGeoWorking = isGeoWorkingRef.value;
4718
- isGeoWorkingRef.value = false;
4722
+ navigator.geolocation.clearWatch(watchId);
4723
+ if (geoError.code === 3 && !!prevGeoPosition) {
4724
+ console.warn("警告: navigator.geolocation.watchPosition 超时跳过");
4725
+ resolve(prevGeoPosition);
4726
+ return;
4727
+ }
4728
+ const { message } = geoError;
4729
+ const prevMessage = geoErrorMessage;
4730
+ geoErrorMessage = message;
4719
4731
  resolve(void 0);
4720
- if (!isGeoWorking)
4732
+ if (prevMessage === message)
4721
4733
  return;
4722
- console.warn(
4723
- "MyWarning: navigator.geolocation.getCurrentPosition failed: ",
4724
- geoError.message
4725
- );
4734
+ console.warn("MyWarning: navigator.geolocation.watchPosition failed: ", message);
4726
4735
  onError == null ? void 0 : onError(geoError);
4727
4736
  },
4728
4737
  option
@@ -4743,8 +4752,8 @@ function androidWatchPosition(onSuccess, onError, option) {
4743
4752
  function compatibleWathPosition(onSuccess, onError, option) {
4744
4753
  const isForceBrowserGeo = takeIsForceBrowserGeo();
4745
4754
  if (isForceBrowserGeo) {
4746
- const watchId2 = navigator.geolocation.watchPosition(onSuccess, onError, option);
4747
- return () => navigator.geolocation.clearWatch(watchId2);
4755
+ const watchId = navigator.geolocation.watchPosition(onSuccess, onError, option);
4756
+ return () => navigator.geolocation.clearWatch(watchId);
4748
4757
  }
4749
4758
  const browserPlatform = detectBrowserPlatform();
4750
4759
  const osPlatform = detectOSPlatform();
@@ -4758,11 +4767,7 @@ function compatibleWathPosition(onSuccess, onError, option) {
4758
4767
  if (browserPlatform === BRWOSER_PLATFORM.ALIPAY || browserPlatform == BRWOSER_PLATFORM.ALIPAY_MINIPROGRAM) {
4759
4768
  return alipayWatchPosition(onSuccess, onError, option, (props) => my.getLocation(props));
4760
4769
  }
4761
- if (osPlatform === OS_PLATFORM.ANDROID) {
4762
- return androidWatchPosition(onSuccess, onError, option);
4763
- }
4764
- const watchId = navigator.geolocation.watchPosition(onSuccess, onError, option);
4765
- return () => navigator.geolocation.clearWatch(watchId);
4770
+ return androidWatchPosition(onSuccess, onError, option);
4766
4771
  }
4767
4772
  function compatibleGeoPositionTransform(position, transform2) {
4768
4773
  const os = detectOSPlatform();
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ if (typeof GeolocationPositionError === "undefined") {
17
17
  };
18
18
  }
19
19
  const name = "@heycar/heycars-map";
20
- const version = "0.9.20-timeout4";
20
+ const version = "0.9.21-alpha2";
21
21
  const type = "module";
22
22
  const bin = {
23
23
  checkVersion: "./bin/checkVersion.js"
@@ -4552,7 +4552,8 @@ function wechatWatchPosition(onSuccess, onError, option) {
4552
4552
  const { timeout } = option;
4553
4553
  let enable = true;
4554
4554
  let prevGeoPosition = void 0;
4555
- const isGeoWorkingRef = ref(true);
4555
+ let lastSuccessfulResponse = void 0;
4556
+ let geoErrorMessage = void 0;
4556
4557
  const { visibilityStateRef, unwatchVisibilityState } = watchVisibilityState();
4557
4558
  const startWatch = async () => {
4558
4559
  try {
@@ -4581,26 +4582,24 @@ function wechatWatchPosition(onSuccess, onError, option) {
4581
4582
  if (isHandled)
4582
4583
  return;
4583
4584
  isHandled = true;
4584
- isGeoWorkingRef.value = true;
4585
+ lastSuccessfulResponse = res;
4586
+ geoErrorMessage = void 0;
4585
4587
  resolve(wxGetLocationSuccessResponse2GeolocationPosition(res));
4586
4588
  },
4587
4589
  fail(res) {
4588
4590
  if (isHandled)
4589
4591
  return;
4590
4592
  isHandled = true;
4591
- const isGeoWorking = isGeoWorkingRef.value;
4592
- isGeoWorkingRef.value = false;
4593
- console.warn(
4594
- "MyWarning: wx.getLocation failed errcode, errmsg = ",
4595
- res.errCode,
4596
- res.errMsg
4597
- );
4593
+ const { errMsg: message, errCode: code } = res;
4594
+ const prevMessage = geoErrorMessage;
4595
+ geoErrorMessage = message;
4598
4596
  resolve(void 0);
4599
- if (!isGeoWorking)
4597
+ if (prevMessage === message)
4600
4598
  return;
4599
+ console.warn("MyWarning: wx.getLocation failed code, message = ", code, message);
4601
4600
  onError == null ? void 0 : onError(
4602
4601
  createCustomGeolocationPositionError(
4603
- res.errMsg,
4602
+ message,
4604
4603
  GeolocationPositionError.PERMISSION_DENIED
4605
4604
  )
4606
4605
  );
@@ -4611,12 +4610,21 @@ function wechatWatchPosition(onSuccess, onError, option) {
4611
4610
  setTimeout(() => {
4612
4611
  if (isHandled)
4613
4612
  return;
4613
+ if (lastSuccessfulResponse) {
4614
+ console.warn("警告: my.getLocation failed with errcode 13 which has been bypassed");
4615
+ return resolve(
4616
+ wxGetLocationSuccessResponse2GeolocationPosition(lastSuccessfulResponse)
4617
+ );
4618
+ }
4619
+ const message = `Custom Timeout: exceed ${timeout}s`;
4620
+ const prevMessage = geoErrorMessage;
4621
+ geoErrorMessage = message;
4614
4622
  resolve(void 0);
4623
+ if (prevMessage === message)
4624
+ return;
4625
+ console.warn("MyWarning: wx.getLocation 触发自定义超时, message = ", message);
4615
4626
  onError == null ? void 0 : onError(
4616
- createCustomGeolocationPositionError(
4617
- `Custom Timeout: exceed ${timeout}s`,
4618
- GeolocationPositionError.TIMEOUT
4619
- )
4627
+ createCustomGeolocationPositionError(message, GeolocationPositionError.TIMEOUT)
4620
4628
  );
4621
4629
  }, timeout);
4622
4630
  });
@@ -4635,9 +4643,9 @@ function wechatWatchPosition(onSuccess, onError, option) {
4635
4643
  function alipayWatchPosition(onSuccess, onError, option, getLocationFn) {
4636
4644
  let enable = true;
4637
4645
  let prevGeoPosition = void 0;
4646
+ let lastSuccessfulResponse = void 0;
4647
+ let geoErrorMessage = void 0;
4638
4648
  const { timeout = ALIPAY_GEO_CACHE_TIMEOUT } = option;
4639
- const isGeoWorkingRef = ref(true);
4640
- const lastSuccessfulResponseRef = ref();
4641
4649
  const { visibilityStateRef, unwatchVisibilityState } = watchVisibilityState();
4642
4650
  const startWatch = async () => {
4643
4651
  do {
@@ -4647,8 +4655,8 @@ function alipayWatchPosition(onSuccess, onError, option, getLocationFn) {
4647
4655
  }
4648
4656
  const geoPosition = await new Promise((resolve) => {
4649
4657
  const handleSuccess = (res) => {
4650
- lastSuccessfulResponseRef.value = res;
4651
- isGeoWorkingRef.value = true;
4658
+ lastSuccessfulResponse = res;
4659
+ geoErrorMessage = void 0;
4652
4660
  resolve(alipayMyGetLocationSuccessResponse2GeolocationPosition(res));
4653
4661
  };
4654
4662
  getLocationFn({
@@ -4656,25 +4664,21 @@ function alipayWatchPosition(onSuccess, onError, option, getLocationFn) {
4656
4664
  cacheTimeout: timeout / 1e3,
4657
4665
  success: handleSuccess,
4658
4666
  fail(res) {
4659
- if (res.error === 13 && lastSuccessfulResponseRef.value) {
4660
- console.warn(
4661
- "MyWarning: my.getLocation failed with errcode 13 which has been bypassed"
4667
+ if (res.error === 13 && lastSuccessfulResponse) {
4668
+ console.warn("警告: my.getLocation failed with errcode 13 which has been bypassed");
4669
+ return resolve(
4670
+ alipayMyGetLocationSuccessResponse2GeolocationPosition(lastSuccessfulResponse)
4662
4671
  );
4663
- return handleSuccess(lastSuccessfulResponseRef.value);
4664
4672
  }
4665
- const isGeoWorking = isGeoWorkingRef.value;
4666
- isGeoWorkingRef.value = false;
4673
+ const { errorMessage: message, error: code } = res;
4674
+ const prevMessage = geoErrorMessage;
4675
+ geoErrorMessage = message;
4667
4676
  resolve(void 0);
4668
- if (!isGeoWorking)
4677
+ if (prevMessage === message)
4669
4678
  return;
4670
- const { error, errorMessage } = res;
4671
- console.warn(
4672
- "MyWarning: my.getLocation failed errcode, errmsg = ",
4673
- error,
4674
- errorMessage
4675
- );
4676
- const geoErrorCode = alipayMyGetLocationError2GeolocationPositionErrorCode(error);
4677
- onError == null ? void 0 : onError(createCustomGeolocationPositionError(errorMessage, geoErrorCode));
4679
+ console.warn("MyWarning: my.getLocation failed code, message = ", code, message);
4680
+ const geoErrorCode = alipayMyGetLocationError2GeolocationPositionErrorCode(code);
4681
+ onError == null ? void 0 : onError(createCustomGeolocationPositionError(message, geoErrorCode));
4678
4682
  }
4679
4683
  });
4680
4684
  });
@@ -4697,7 +4701,7 @@ const apGetLocation = ({ type: type2, cacheTimeout, success, fail }) => {
4697
4701
  function androidWatchPosition(onSuccess, onError, option) {
4698
4702
  let enable = true;
4699
4703
  let prevGeoPosition = void 0;
4700
- const isGeoWorkingRef = ref(true);
4704
+ let geoErrorMessage = void 0;
4701
4705
  const { visibilityStateRef, unwatchVisibilityState } = watchVisibilityState();
4702
4706
  const startWatch = async () => {
4703
4707
  do {
@@ -4706,21 +4710,26 @@ function androidWatchPosition(onSuccess, onError, option) {
4706
4710
  continue;
4707
4711
  }
4708
4712
  const geoPosition = await new Promise((resolve) => {
4709
- navigator.geolocation.getCurrentPosition(
4713
+ const watchId = navigator.geolocation.watchPosition(
4710
4714
  function onSuccess2(geoLocationPosition) {
4711
- isGeoWorkingRef.value = true;
4715
+ navigator.geolocation.clearWatch(watchId);
4716
+ geoErrorMessage = void 0;
4712
4717
  resolve(geoLocationPosition);
4713
4718
  },
4714
4719
  function onFail(geoError) {
4715
- const isGeoWorking = isGeoWorkingRef.value;
4716
- isGeoWorkingRef.value = false;
4720
+ navigator.geolocation.clearWatch(watchId);
4721
+ if (geoError.code === 3 && !!prevGeoPosition) {
4722
+ console.warn("警告: navigator.geolocation.watchPosition 超时跳过");
4723
+ resolve(prevGeoPosition);
4724
+ return;
4725
+ }
4726
+ const { message } = geoError;
4727
+ const prevMessage = geoErrorMessage;
4728
+ geoErrorMessage = message;
4717
4729
  resolve(void 0);
4718
- if (!isGeoWorking)
4730
+ if (prevMessage === message)
4719
4731
  return;
4720
- console.warn(
4721
- "MyWarning: navigator.geolocation.getCurrentPosition failed: ",
4722
- geoError.message
4723
- );
4732
+ console.warn("MyWarning: navigator.geolocation.watchPosition failed: ", message);
4724
4733
  onError == null ? void 0 : onError(geoError);
4725
4734
  },
4726
4735
  option
@@ -4741,8 +4750,8 @@ function androidWatchPosition(onSuccess, onError, option) {
4741
4750
  function compatibleWathPosition(onSuccess, onError, option) {
4742
4751
  const isForceBrowserGeo = takeIsForceBrowserGeo();
4743
4752
  if (isForceBrowserGeo) {
4744
- const watchId2 = navigator.geolocation.watchPosition(onSuccess, onError, option);
4745
- return () => navigator.geolocation.clearWatch(watchId2);
4753
+ const watchId = navigator.geolocation.watchPosition(onSuccess, onError, option);
4754
+ return () => navigator.geolocation.clearWatch(watchId);
4746
4755
  }
4747
4756
  const browserPlatform = detectBrowserPlatform();
4748
4757
  const osPlatform = detectOSPlatform();
@@ -4756,11 +4765,7 @@ function compatibleWathPosition(onSuccess, onError, option) {
4756
4765
  if (browserPlatform === BRWOSER_PLATFORM.ALIPAY || browserPlatform == BRWOSER_PLATFORM.ALIPAY_MINIPROGRAM) {
4757
4766
  return alipayWatchPosition(onSuccess, onError, option, (props) => my.getLocation(props));
4758
4767
  }
4759
- if (osPlatform === OS_PLATFORM.ANDROID) {
4760
- return androidWatchPosition(onSuccess, onError, option);
4761
- }
4762
- const watchId = navigator.geolocation.watchPosition(onSuccess, onError, option);
4763
- return () => navigator.geolocation.clearWatch(watchId);
4768
+ return androidWatchPosition(onSuccess, onError, option);
4764
4769
  }
4765
4770
  function compatibleGeoPositionTransform(position, transform2) {
4766
4771
  const os = detectOSPlatform();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heycar/heycars-map",
3
- "version": "0.9.20-timeout4",
3
+ "version": "0.9.21-alpha2",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "checkVersion": "./bin/checkVersion.js"