我正在开发天气应用程序。为此,我想按城市搜索天气。我按城市获取天气信息,但问题是 即;在我输入类似的搜索框中 例如:dfdfdfdf(或)12435我收到天气信息。不应该发生它应该只检索城市的天气信息。我已经编辑了我的代码。以下是完整代码
.controller('SearchInWeatherH01Ctrl', function ($scope, $state, Weather, $resource, $http,$rootScope) {
$scope.checkWeather = function (city) {
$http.get("https://maps.googleapis.com/maps/api/geocode/json?address=" + encodeURIComponent(city))
.success(function (response) {
if (response.results.length) {
if (response.results.length) {
var location = response.results[0].geometry.location;
$scope.lat = location.lat;
$scope.longit = location.lng;
Weather.getAtLocation(location.lat, location.lng).then(function (resp) {
if (city == null ) {
alert("Please Enter City Name");
return false;
}
$scope.current = resp.data;
console.log('GOT CURRENT',JSON.stringify( $scope.current));
$rootScope.$broadcast('scroll.refreshComplete');
}, function (error) {
alert('Unable to get current conditions');
console.error(error);
});
}
});
}
})