语言

Menu
Sites
Language
Detect location request prompt

I am building an app that requires access to the users location and it uses the getCurrentLocation code snippet from https://developer.tizen.org/documentation/articles/using-location-based-services-on-tizen.  When the app is opened for the first time and it attempts to determine the user's location, the user receives a prompt that says, "<app name> requests your location".  This prompt also shows up on subsequent loads if the user does not choose to remember this setting.

I've seen apps on other platforms where it takes 5+ seconds to determine the users location for any number of reasons.  I would like to gracefully handle this by triggering a possible user override if the app still has not determined the location after X seconds.  Triggering the override is straightforward but I was curious if there was any sort of callback that I could tie into when a user chooses "Yes" or "No" in response to the prompt?  

Thanks in advance

响应

3 回复
Marco Buettner

interface Geolocation { void getCurrentPosition(PositionCallback successCallback, optional PositionErrorCallback errorCallback, optional PositionOptions options); Why so complicate? The getCurrentPosition allows successCallback, errorCallback and Options.. On Options you can set a timeout of >5 Seconds. And on the errorCallback you can handle this error example

function onSuccess(pos)
{
	// TODO: write your success code here
}

function onError(err)
{
	switch(err.code)
	{
		case error.TIMEOUT:
			var userConfirm = confirm('<app name> was unable to find you position. Try again?');
			if(userConfirm)
				navigator.geolocation.getCurrentPosition(onSuccess, onError);
          	break;
	}
}

var options = {timeout:5500}; // set timeout to 5,5 seconds
navigator.geolocation.getCurrentPosition(onSuccess, onError, options);
Matt Alonso

Well there ya go.  Thanks Marco.  Somehow I missed the options element when reading the docs.

 

Marco Buettner

Sometimes I read to fast the docs, too :D