Google Map Functions Over Secure Network

If we use any of the Google Map functions such as getCurrentLocation on navigator, it throws an error if it is not accessed over a secure origin.

PS: localhost is treated as a secure origin over HTTP, so if you’re able to run your server from localhost, you should be able to test the feature on that server.

As we can’t have an HTTPS Certificate for a test server, we can configure it to be over HTTPS by using Self Signed Certificates.

Here is the link to generate self-signed certificates on a ubuntu machine

Then, you will have to configure Nginx over SSL and here is a code snippet for that:

server {

            listen 443 ssl;
            server_name ;
            underscores_in_headers on;
            ssl_certificate ;
            ssl_certificate_key  ;


If you want to redirect an HTTP request to HTTPS on Nginx, you can do it this way:

server {
listen 80;
return 301 https://$server_name$request_uri;

Above method will let you enable google map functions over secure network.
By – Neeraj Joshi, Senior Software Developer

adminGoogle Map Functions Over Secure Network
Share this post

Join the conversation

Related Posts