1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Rep Power

    Error not displaying?

    Hi have a geolocation script (using google maps...) and thanks to web_loone08 I was able to properly implement it... the problem now seems to be that if the user chooses NOT to share their location, the page just hangs as if it's waiting still, and doesn't display the error message and I'm not sure why...?

    <section id="wrapper">
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <p><span id="status"><img src="loading.gif" alt="Loading" width="43" height="11" style="margin:2px 6px;"  />Finding your location...</span></p>
    function success(position) {
     var s = document.querySelector('#status');
      if (s.className == 'success') {
      //Message after tracing the location
      s.innerHTML = "Here you are!";
      s.className = 'success';
      var mapcanvas = document.createElement('div');
      mapcanvas.id = 'mapcontainer';
      mapcanvas.style.height = '400px';
      mapcanvas.style.width = '700px';
      var coords = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
      var options = {
        zoom: 15,
        center: coords,
        mapTypeControl: false,
        navigationControlOptions: {
        	style: google.maps.NavigationControlStyle.SMALL
        mapTypeId: google.maps.MapTypeId.ROADMAP
      var map = new google.maps.Map(document.getElementById("mapcontainer"), options);
      var marker = new google.maps.Marker({
          position: coords,
          map: map,
          title:"You are here!"
    document.getElementById("ur_here").innerHTML = "You are located at the following: " + coords.toString().replace("(","Latitude:").replace(","," | Longitude:").split(")")[0];
    if (navigator.geolocation) {
    } else {
      error('Geo Location is not supported');
    <div id="ur_here"></div>
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Rep Power
    Check this out; it might help you with this:http://diveintohtml5.info/geolocation.html#errors.

    PS: You could always go the server side route and then you do not have to ask them for their location; you can display the location without granted permission (I will probably get some flack about this statement => oh, well lol; but it can be done).
    Last edited by web_loone08; June 15th, 2013 at 12:00 AM.

IMN logo majestic logo threadwatch logo seochat tools logo