2

I'm coding a web app which is using by maps. I want to find visitor's location. It is working on firefox but not working on chrome. Chrome says "it is blocked that track your location by this page." How can i fix it for chrome?

        function onPositionUpdate(position)
        {
            var lat = position.coords.latitude;
            var lng = position.coords.longitude;
            alert("Current position: " + lat + " " + lng);
        }

        if(navigator.geolocation)
            navigator.geolocation.getCurrentPosition(onPositionUpdate);
        else
            alert("navigator.geolocation is not available");

and now I try this:

function get_location() {

        if (geo_position_js.init()) {
            geo_position_js.getCurrentPosition(show_map, handle_error);
        }

    }
    function show_map(position) {
        var latitude = position.coords.latitude;
        var longitude = position.coords.longitude;

        alert("lat:" + latitude + " long:" + longitude);


    }
    function handle_error(err) {
        alert(err.code);
        if (err.code == 1) {
            // user said no!
        }
    }

    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(show_map, handle_error);
    } else {
        error('not supported');
    }

When I run this with chrome I get "javascript alert 1" error. It is working on firefox.

Edit: I solve this problem by using html5 geolocation http://www.w3schools.com/html/html5_geolocation.asp

2 Answers2

2

Type on address bar: chrome://settings/content

SeinopSys
  • 8,787
  • 10
  • 62
  • 110
Chưa biết
  • 919
  • 8
  • 6
0

Some features only be accessible on "secure origins" (such as HTTPS) where the full ancestor chain is also secure.

https://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins

gtzinos
  • 1,205
  • 15
  • 27