我在app.js中有下面的代码。我想捕捉$scope.city变量中的位置城市。我已经宣布了城市外的地理代码功能,但是城市并没有得到任何价值。需要你的帮助
// code as below
app.controller('ydmoreCtrl', function($scope, $timeout, $ionicModal, $ionicSideMenuDelegate, Categories) {
(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position){
var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
var geocoder = new google.maps.Geocoder();
var city;
geocoder.geocode({'latLng': latlng}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
if (results[0])
{
var add= results[0].formatted_address ;
var value=add.split(",");
count=value.length;
country=value[count-1];
state=value[count-2];
city=value[count-3];
callback(latlng);
// alert(city);
}
else
{
alert("address not found");
}
}
});
$scope.$apply(function(){
$scope.city = "Pune";
});
});
}
/*
*/发布于 2015-01-26 08:20:20
你可以试着打电话
$scope.apply()
在城市被设置为
$scope.city
内部到geocoder.geocode调用
https://stackoverflow.com/questions/28146449
复制相似问题