Http sites does not detect the location in Chrome - issue

13,060

Solution 1

The new Security rule introduced in Chrome 50 does not send Location Information to Sites without Transfer Encryption.

Here are the alternatives which are apt for the Mapping API problems.

Reverting to Prior versions of the Chrome(50) is also a solution, but in Web development, it is quite difficult to do so.

But the fact is that, currently only Chrome has such issues with Mapping API and other Browsers still supports them(Which gives me a short term peace of mind).

But sooner or later, this may be practiced by other browsers too, which may be a big problem for the existing users unlike me. Since it is a long term process(in my case), it is better to start developing and migrating to https sites rather than being in http, how ever there are pros and cons in handling them.

Solution 2

You cannot use the HTML5 Geolocation API with non-secure connections as per below:

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.

However, it is possible to use the Google Maps Geolocation API or GeoIP, and possibly others, though it is not recommended in the long term. See below:

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.

Source: Geolocation API removed from unsecured origins in Chrome 50

Solution 3

I know this isn't a place to debate but this answer probably represent most of programmers that have been implemented geolocation in their applications.

As stated in other answers "Geolocation API removed from unsecured origins in Chrome 50".
Well that is a weird move by Google.
They claim that the changes are due to user privacy.

This seriously compromises user privacy.

Google cares about user privacy(laughs).
I have developed numerous of applications (CMS plugins, standalone application templates) using HTML5 Geolocation API for public use.
I can't really say to 1000 users to get an SSL certificate.

From my point of view Google is trying to make internet more expensive and inaccessible for most of independent developers and "superusers".

Alternatives are:

  • Using geolocation API from Google(limited requests, pay for more)

  • Get a paid service.

  • Get and install an SSL cert

I tried to load the geolocation script from an HTTPS location on the same server and from public accessed CDNs (github) but the same error appeared.
Chrome requires an SSL installed on the website too.

Share:
13,060
Ruban J
Author by

Ruban J

Working as a Senior Software Developer. Eager to explore Knowledge and to share with everyone. :)

Updated on June 07, 2022

Comments

  • Ruban J
    Ruban J almost 2 years

    We did notice today an issue in automatic detection of zip code based on the user s location. it worked well in other browsers(edge, IE, Firefox) We had to configure the sites to https and then it works ok

    Example : https://www.whatismyzip.com/ works well where as http://www.mapdevelopers.com/what-is-my-zip-code.php does'nt work.

      <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAdGQKI4sEj5TZAjNCds422V_ZHevD45Fo"></script>
     <%--   <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"></script>--%>
    
     <%--     <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?libraries=places"></script>
     <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>--%>
        <script type="text/javascript">
    
    
            function ShowMessages() {
    
                debugger;
                if (navigator.geolocation) {
                    navigator.geolocation.getCurrentPosition(success);
                } else {
                    alert("Geo Location is not supported on your current browser!");
                }
                function success(position) {
                    debugger;
                    var lat = position.coords.latitude;
                    var lng = position.coords.longitude;
                    var latlng = new google.maps.LatLng(lat, lng);
                    var geocoder = geocoder = new google.maps.Geocoder();
                    geocoder.geocode({ 'latLng': latlng }, function (results, status) {
                        if (status == google.maps.GeocoderStatus.OK) {
                            if (results[1]) {
    
                                var searchAddressComponents = results[0].address_components,
                                 searchPostalCode = "";
                                $.each(searchAddressComponents, function () {
                                    if (this.types[0] == "postal_code") {
                                        searchPostalCode = this.short_name;
                                    }
                                });
    
                                document.getElementById('hidden1').value = searchPostalCode
                                __doPostBack('', '');
    
    
                            }
                        }
                    });
                }
    
            }
    

    Any help/workaround would be appreciated.

    EDIT: Other than Google API, are there any other working alternatives?

  • MacK
    MacK almost 8 years
    There are no code snippets. You must host your script with the geolocation API into a HTTPS environment and then retrieve the data from there on your HTTP page. Otherwise you can query a third-party API to get the user location and re-use it on your page.
  • fat_mike
    fat_mike almost 8 years
    @MacK You can't host the script in an SSL environment and get the results in an HTTP page. Tried it and doesn't work. SSL must be present in the page too.
  • Ruban J
    Ruban J almost 8 years
    I second that. A weird move by Google.