Amap ios location problem

I first met this kind of problem When the ios version of the testing machine is IOS12 first reaction is to Google The boy had a lot of friends all records

If (amap.ua.ios) {// To use remote location, see remogeo. Js var remogeo = new RemoGeoLocation(); / / replace method the navigator. Geolocation. GetCurrentPosition = function () {return remoGeo. GetCurrentPosition. Apply (remoGeo, arguments); }; / / replace method the navigator. Geolocation. WatchPosition = function () {return remoGeo. WatchPosition. Apply (remoGeo, the arguments); }; }Copy the code

Take a look at autonavi’s official website solution

Basically the same as the official solution found on the Internet, the remote location solution was used to get started and worked perfectly on the test machine

Good times did not last 21 years in July IOS15 released not long after the business reflected IOS15 can not be positioned. Why is it such a similar scene

Start to find the problem and look at the code first to locate the module code basically unchanged and then run in ios15 under the system no problem or continue to Google

It’s not going to be as easy as it was last time because a lot of people on the Internet have this problem and it’s not going to be solved

If you can’t find it, keep checking the official API

I used this page to test the address and I found the same problem that I’ve had so far. I can locate IOS15 but I can’t locate IOS15. Then I noticed that the location test page is HTTP.HTTPS Location address

After the test machine was tested, the positioning was successful and the solution to the problem was found

1. Open the console to find the difference code in the page where the test location is successful. In HTTPS environment, remote location will not be used.

/ switch/ios environment to use remote HTTPS positioning the if (AMap) UA) ios && document. The location. The protocol! Js var remogeo = new RemoGeoLocation(); / / replace method the navigator. Geolocation. GetCurrentPosition = function () {return remoGeo. GetCurrentPosition. Apply (remoGeo, arguments); }; / / replace method the navigator. Geolocation. WatchPosition = function () {return remoGeo. WatchPosition. Apply (remoGeo, the arguments); }; }Copy the code

2. The fault location test cannot be performed in the HTTP environment, but can be performed only in HTTPS

Change the code to publish online online perfect solution to the problem

Some ios14 versions of Alert cannot close the problem

With a small episode at that time to solve the first version of ios positioning problem also encountered positioning failure alert box can not close the problem.

Check the code to find this alert box is the map with the alert box ah…

It’s hard for me. I have Google in my hand

Looking for a long time many have no solution this is a very detailed explanation

You get the idea that the JS thread and the iOS alert view thread might block each other, making the “Close” button unresponsive

And since this alert is inside the map API I’m going to replace alert globally

Window.alert = function(name){setTimeout(()=>{var iframe = document.createElement("IFRAME"); iframe.style.display="none"; iframe.setAttribute("src", 'data:text/plain,'); document.documentElement.appendChild(iframe); window.frames[0].window.alert(name); iframe.parentNode.removeChild(iframe); }}, 100);Copy the code

Release to test perfect solution

No such problems were found in subsequent IOS15 releases