Pedro Teixeira
Pedro Teixeira

Reputation: 3

The geolocation isnt working on mobile but works on my desktop

Im trying to implement geolocation on my project, I already have the api and stuff, all the code necessary, but on mobile whenever I try to access the location it just show and error on the google maps saying "Error: The geolocation service failed." but on my desktop it works fine.

code here

Was expecting the same thing that happens on my desktop, a prompt asking for permission to access gps but nothing happens

Upvotes: 0

Views: 371

Answers (1)

Haseeb Afsar
Haseeb Afsar

Reputation: 629

@Pedro Teixeira - If you're running this app from a web server not as a local HTML page. Here is why this is not working for you.

Why Geolocation will not work if your site is not HTTPS or atleast the page you'r calling geolocation is not HTTPS? Chrome has public intent to deprecate powerful features like geolocation on non-secure origins, and we hope that others will follow.

Starting with Chrome 50, Chrome no longer supports obtaining the user's location using the HTML5 Geolocation API from pages delivered by non-secure connections. This means that the page that's making the Geolocation API call must be served from a secure context such as HTTPS.

It is an important issue as it will directly impact any site that requires use of the geolocation API and is not served over https, but it is a change that we do believe is beneficial to all users on the web. This post should help you understand the reasoning and how to proceed.

Since when this change is effective? This change is effective as of Chrome 50 (12PM PST April 20 2016).

Why are we making this change? Location is sensitive data! Requiring HTTPS is required to protect the privacy of your users' location data. If the user's location is available from a non-secure context, attackers on the network will be able to know where that user is. This seriously compromises user privacy.

Who does this affect? This affects any page currently using the Geolocation API from pages served over HTTP (non-secure). It also affects HTTPS iframes that use the Geolocation API if they are embedded in HTTP pages. (You won't be able to polyfill using a shared HTTPS-delivered frame.)

Response on the Google Developer Site

If you would like to use the HTML5 Geolocation API, or if your site already uses the Geolocation API, please migrate the pages making Geolocation API calls to HTTPS, ensuring that they're used in a secure context.

There are a number of fallback options available to get a user's location that are not affected by this change, such as Google Maps Geolocation API, GeoIP (as an example, there are other geo based solutions), and a user-entered zip code. However, we strongly recommend that the best path to ensure ongoing access to geolocation is to move to HTTPS.

Please follow this link for more information https://developers.google.com/web/updates/2016/04/geolocation-on-secure-contexts-only

Upvotes: 2

Related Questions