Tuesday 15 July 2014

javascript - where to put enableHighAccuracy and other settings for geolocation -



javascript - where to put enableHighAccuracy and other settings for geolocation -

i have next code gets geo location , posts it, displays button in div. works on desktops not work in android mutual issue mentioned on site. recommendations add together

{frequency:5000, maximumage: 0, timeout: 100, enablehighaccuracy:true}

to code below somewhere, i've tried few places stops working, set these values please?

function getcoordposition() { if (navigator.geolocation) { navigator.geolocation.getcurrentposition( function (position) { $.ajax({ type: "post", url: "{{path('login_log_location')}}", data: { latitude: position.coords.latitude, longitude: position.coords.longitude }, success: function () { $("#divputinarea").html("{{path('login_log_yourarea')}}"> <button class="btn btn-large btn-primary"> find </button>'); } }); }); } }

after advice below tried following, works without { maximumage: 0,timeout: 100,enablehighaccuracy:true} if add together error 'argument 2 of geolocation.getcurrentposition not callable"

function getcoordposition() { if (navigator.geolocation) { function getposition(position) { $.post("{{path('login_log_location')}}", { latitude:position.coords.latitude, longitude:position.coords.longitude }) .done(function(data) { $("#divputinarea").html('<form method=post action=" {{path('login_log_yourarea')}}"><button class="btn btn-large btn-primary">find nearest matches</button>'); }); } navigator.geolocation.getcurrentposition(getposition, { maximumage: 0,timeout: 100,enablehighaccuracy:true} ); } } </script>

the getcurrentposition method takes 3 parameters: success callback, error callback , object containing configuration parameters.

navigator.geolocation.getcurrentposition( successcallback, errorcallback, {frequency:5000, maximumage: 0, timeout: 100, enablehighaccuracy:true} );

here's jsfiddle.

edit: can modify code define these 3 parameters.

function getposition(position) { $.post("{{path('login_log_location')}}", { latitude:position.coords.latitude, longitude:position.coords.longitude }) .done(function(data) { $("#divputinarea").html('<form method=post action=" {{path('login_log_yourarea')}}"><button class="btn btn-large btn-primary">find nearest matches</button>'); }); } function onerror(positionerror) { // error handling goes here } function getcoordposition() { if (navigator.geolocation) { navigator.geolocation.getcurrentposition( getposition, // success callback onerror, // error callback {maximumage: 0,timeout: 100,enablehighaccuracy:true} // params ); } }

javascript android jquery geolocation

No comments:

Post a Comment