@claudiocarmeli wrote:
Hello,
In my app, I have to figure out where the user is, so that I can send
latandlngas query parameters with my $resource request.
This is my code:angular.module('starter.services', ['ngResource']) .factory('Pubs', function($resource) { // Get user position navigator.geolocation.getCurrentPosition(getPosition); function getPosition(position) { // Get pubs var httpRequest = $resource('http://my-domain.com/pubs', {}, { query: { method: 'GET', isArray: true, params: { lat: position.coords.latitude, lng: position.coords.longitude } } }); pubs = httpRequest.query(function(response) { console.log(response); }); } return { all: function() { return pubs; } }; });It doesn't work because by the time that HTML5 Geocoding has got back to me with the coordinates, the function has already returned. Moving all the code inside the callback does not work because I get an error saying 'your services must return something'. I know it's quite simple but I am stuck...
Any help would be greatly apreciated
Posts: 1
Participants: 1