Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Sep 2013
    Posts
    25
    Thanks
    8
    Thanked 1 Time in 1 Post

    Unhappy Reference error on Firefox but not IE??!

    I've been getting a reference error on firefox but not IE for a Geolocation code that I have. Console reports success is not defined? For some reason, my code works fine on IE but not on chrome or firefox. A little insight to why this might happen would be appreciated:
    Code listed below:
    Code:
    function displayMe(){
    
            navigator.geolocation.getCurrentPosition(success);
        console.log("Got to displayME");
            if(!!navigator.geolocation) {
            function success(position) {
                console.log("navigator has geolocation");
    
                var coords = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
                var marker = new google.maps.Marker({
                      position: coords,
                      map: map,
                      title:"You are here!",
                      animation: google.maps.Animation.BOUNCE
                  });
              }
              
          function error_handle(error)
      {
    
      switch(error.code) 
        {
        case error.PERMISSION_DENIED:
          alert("User denied the request for Geolocation.");
          break;
        case error.POSITION_UNAVAILABLE:
          alert("User's Position is Unavailable.");
          break;
        case error.TIMEOUT:
          alert("User Timeout.");
          break;
        case error.UNKNOWN_ERROR:
          alert("User Request Failed due to unknown Error.");
          break;
        }
      }  
              
        }
    }

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,965
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Try this:
    Code:
    function displayMe() {   
        console.log("Got to displayME");
        if ( !! navigator.geolocation) {
    
             navigator.geolocation.getCurrentPosition(success);
    
            function success(position) {
                console.log("navigator has geolocation");
    
                var coords = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
                var marker = new google.maps.Marker({
                    position: coords,
                    map: map,
                    title: "You are here!",
                    animation: google.maps.Animation.BOUNCE
                });
            }
    
            function error_handle(error) {
    
                switch (error.code) {
                case error.PERMISSION_DENIED:
                    alert("User denied the request for Geolocation.");
                    break;
                case error.POSITION_UNAVAILABLE:
                    alert("User's Position is Unavailable.");
                    break;
                case error.TIMEOUT:
                    alert("User Timeout.");
                    break;
                case error.UNKNOWN_ERROR:
                    alert("User Request Failed due to unknown Error.");
                    break;
                }
            }
    
        }
    }

  • Users who have thanked glenngv for this post:

    and0rsk (09-19-2013)

  • #3
    New Coder
    Join Date
    Sep 2013
    Posts
    25
    Thanks
    8
    Thanked 1 Time in 1 Post
    Putting the getCurrentPosition within the geolocation if statement was definitely a better way to do it. Unfortunately I still have the same problem. It's actually quite weird. On IE the program works fine. On chrome I get the error that positioning isn't supported (at least the error is showing). But on Firefox I don't get an error that I inputted, but a no referenced error. I'm really curious as to whether this is a browser problem or a programming problem on my end.

    Quote Originally Posted by glenngv View Post
    Try this:
    Code:
    function displayMe() {   
        console.log("Got to displayME");
        if ( !! navigator.geolocation) {
    
             navigator.geolocation.getCurrentPosition(success);
    
            function success(position) {
                console.log("navigator has geolocation");
    
                var coords = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
                var marker = new google.maps.Marker({
                    position: coords,
                    map: map,
                    title: "You are here!",
                    animation: google.maps.Animation.BOUNCE
                });
            }
    
            function error_handle(error) {
    
                switch (error.code) {
                case error.PERMISSION_DENIED:
                    alert("User denied the request for Geolocation.");
                    break;
                case error.POSITION_UNAVAILABLE:
                    alert("User's Position is Unavailable.");
                    break;
                case error.TIMEOUT:
                    alert("User Timeout.");
                    break;
                case error.UNKNOWN_ERROR:
                    alert("User Request Failed due to unknown Error.");
                    break;
                }
            }
    
        }
    }

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,965
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Did the browser ask for permission to get your location and did you allow it?

    Posting a simple page that shows the error will help.

  • #5
    New Coder
    Join Date
    Sep 2013
    Posts
    25
    Thanks
    8
    Thanked 1 Time in 1 Post
    I've noticed that despite clearing my cache and preferences, it doesn't prompt me for user location. hm......

    Quote Originally Posted by glenngv View Post
    Did the browser ask for permission to get your location and did you allow it?

    Posting a simple page that shows the error will help.
    Attached Thumbnails Attached Thumbnails Reference error on Firefox but not IE??!-reference-error.jpg  

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,965
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Can you post a simple page here or on jsfiddle for us to try to reproduce the error?


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •