Skip to content
Advertisement

Why the Google Maps API does not work on a server? [Error: The Geolocation service failed]

Currently I just upload what I have from my website to a test server and it is free, locally if the google maps API works and shows me the location where I am currently. But when I uploaded my website to the server and modified everything necessary to make everything look good, that part of the Google Maps API stopped working correctly.

Google maps api code:

JavaScript

The error that I get is the following:

Error: The Geolocation service failed

I do not modify anything of the script, that remained intact.

Code to put google map:

JavaScript

Code to send the api with its respective key

JavaScript

Current Result

enter image description here

Web console error:

JavaScript

Advertisement

Answer

According to your console error you are hosting the site to an http server and Google maps and the browser geolocation API will only work over https connections. Try uploading your code to a secure server like github pages.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement