我创建了一个工厂方法,当从控制器中检索值时总是返回undefined。当我写日志时,它的值完美,但返回未定义。工厂方法总是在AngularJs中返回undefined
.factory('GetLatLongFromAddress', ['$http', '$q', function ($http, $q) {
var LatnLong =
{
Latitude: 0.00,
Longitude: 0.00
}
return {
GetLatLong: function (address) {
var geocoder = new google.maps.Geocoder();
var address = address;
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK)
{
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
LatnLong.Latitude = latitude;
LatnLong.Longitude = longitude;
console.log(LatnLong);
}
});
setTimeout(function() { }, 3000);
return LatnLong
},
}
}])
而且在myController的其中我打电话是;
$scope.returnValue=(JSON.stringify(GetLatLongFromAddress.GetLatLong("Address")));
所以,你能帮我解决这个问题。
谢谢。
你注射了吗? – Alessio
你能帮我给我更多的细节,因为我是新角 –