I am using AngularJS leaflet to search for a location and obtain latitude and longitude coordinates. In my service, I am calling my code to display map with within the service I wrote a callback which takes (lat,lng) and make an HTTP requests to url to get data related to those coordinates.
Ideally, I would like to have created a function that returned an http request and returns the promise in the controller. The problem is that getMarkets is a callback and I can not call .then on the function directly because it needs to be passed the coordinates first. It is returning the data and I would like to know how to pass the data I receive from ($http(options)) to the controller so I can render response in the view.
app.service('mapService', (function($http) {
var fmCoordinates = {};
var requestMarkets = function(lat,lng){
var options = {
type: "GET",
contentType: "application/json; charset=utf-8",
url: "http://somerul?lat=" + lat + "&lng=" + lng
};
return console.log($http(options));
};
L.Control.Search = L.Control.extend({
//Leaflet Code
_getLocation: function(key) { //extract latlng from _recordsCache
var latLong = this._recordsCache[key];
fmCoordinates.lat = latLong.lat;
fmCoordinates.lng = latLong.lng;
requestMarkets(fmCoordinates.lat,fmCoordinates.lng);
if( this._recordsCache.hasOwnProperty(key) )
return latLong;//then after use .loc attribute
else
return false;
},
})