我有一种地址形式,其中有一个来自googleMaps的输入自动填充功能。当我选择一个地址时,其余的输入都会被填充。这种形式中的两种是纬度和经度。
我希望当我输入地址时,服务$ watch会检测此值并刷新地图。
注意:如果我在该字段中写入,服务$ watch会检测值,但我想写入地址并获取此值。
我的代码表格地址:
<input vs-google-autocomplete="{ types: ['address'] }"
vs-autocomplete-validator="vs-street-address"
ng-model="streetNumber[a.count].name"
vs-place="streetNumber[a.count].place"
vs-place-id="streetNumber[a.count].components.placeId"
vs-street-number="streetNumber[a.count].components.streetNumber"
vs-street="streetNumber[a.count].components.street"
vs-city="streetNumber[a.count].components.city"
vs-state="streetNumber[a.count].components.state"
vs-country-short="streetNumber[a.count].components.countryCode"
vs-country="streetNumber[a.count].components.country"
vs-post-code="streetNumber[a.count].components.postCode"
vs-latitude="streetNumber[a.count].components.location.lat"
vs-longitude="streetNumber[a.count].components.location.long"
type="text"
name="streetNumber"
id="streetNumber"
class="form-control"
placeholder="Enter full address (street number, street, ...)">
<input type="text" id="user_address_{{ ::address.count }}_latitude" name="user[address][{{ ::address.count }}][latitude]"
value="{{streetNumber[a.count].components.location.lat}}" ng-model="latitude" class="form-control">
<input type="text" id="user_address_{{ ::address.count }}_longitude" name="user[address][{{ ::address.count }}][longitude]"
ng-model="longitude" value="{{streetNumber[a.count].components.location.long}}" class="form-control">
<ui-gmap-google-map center='map.center' zoom='map.zoom'></ui-gmap-google-map>
AngularJS:
app.controller("testCtrl",function ($scope) {
$scope.map = { center: { latitude: 40.37464, longitude: -3.7319700000000466 }, zoom: 16 };
$scope.address = {
count: -1
};
$scope.$watch('longitude', function(newLongitude) {
alert('newLongitude');
}, true);
$scope.$watch('latitude', function(newLatitude) {
if (!angular.isUndefined(newLatitude)){
$scope.map['center']['latitude'] = newLatitude;
}
}, true);
});