简体   繁体   中英

How to access geolocation in mobile web browser

I'm used html5 geolocation I made from the documentation

getLocation() {
   if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(this.showPosition, this.showError);
   } else {
       alert("geolocation not support");
   }
},

code working if i'm using chrome (toogle device toolbar) but in mobile browsers chrome(android) safari(ios) showing error

User did not share location

how to fix it ?

On phones geolocation enabled

UPD: Most likely this is due to the fact that there is no ssl certificate ?

Not all browsers have the same APIs built in. So you will have to figure out what browser a client is using and write different code depending on what APIs are included. You can figure out what browser they are using by checking the user agent.

With the latest browser updates to get geolocation, you need to use the

SSL certificates

for safari browser answer from this question helped me

Check which browsers support it at https://whatwebcando.today/ . Also, geo location services may be disabled in OS settings - either overall or per application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM