locked
Don't getting geolocation coordinates but having the option enabled RRS feed

  • Question

  • Hey there,

    I try to get the geolocation api to work and I knew, that I had to enable it into the Windows 8 Preview Release - settings so I did (PC Settings --> Privacy Privacy --> apps are allowed to access my location) (Wording is different, I use Win 8 in German).

    But when I execute the following code it always shows the error code 1 telling me, that I have to enable the Geolocation API.

    requestPosition: function () {
    	var nav = null;
    	if (nav == null) {
    		nav = window.navigator;
    	}
    	
    	if (nav != null) {
    		var geoloc = nav.geolocation;
    		if (geoloc != null) {
    			geoloc.getCurrentPosition(
    				function (position) {
    					document.getElementById("debug").innerText += position.coords.latitude + " :: " + position.coords.longitude;
    				}, 
    				function (error) {
    					var message = "";
    					document.getElementById("debug").innerText += "ERROR: " + error.code.toString();
    					switch (error.code) {
    						case error.PERMISSION_DENIED:
    							message = "You must grant access to the Geolocation API to use this feature!";
    						break;
    						case error.POSITION_UNAVAILABLE:
    							message = "The current position could not be determined. Try again or enter a ZIP-Code instead of using this feature.";
    						break;
    						case error.PERMISSION_DENIED_TIMEOUT:
    							message = "The current position could not be determined due to timeout. Try again or enter a ZIP-Code instead of using this feature.";
    						break;
    					}
    					if (message == "") {
    						message = "Unknown error occurred with code " + error.code.toString() + ". Try again or use ZIP-detecting";
    					}
    					document.getElementById("debug").innerText += message;
    				}
    			);
    		}
    		document.getElementById("debug").innerText = "requestPosition called: " + geoloc;
    	}
    }

    requestPosition is my callback function for the click event on the button where the User shall geolocate himself.

    What am I doing wrong? Do I need to enable the Geolocation API for every Metro App?

     

    Thursday, June 21, 2012 4:51 PM

Answers

All replies