【发布时间】:2015-08-04 05:32:10
【问题描述】:
我是 Angular js 的新手。如何实施地理编码服务?具体来说,当我填写完整地址时,如何自动填充其他字段(postal code,city,country,lat and lng)?
我想在 Angular 中实现类似 this page 的效果。
请帮帮我。
我有填充完整地址的代码:
app.directive('googlePlaces', function(){
return {
restrict:'E',
replace:true,
// transclude:true,
scope: {location:'='},
template: '<input type="text" id="fulladdress" name="fulladdress" ng-model="enterprise.fulladdress" class="form-control text-field" placeholder="">',
link: function($scope, elm, attrs){
var autocomplete = new google.maps.places.Autocomplete($("#country")[0], {});
google.maps.event.addListener(autocomplete, 'place_changed', function() {
var place = autocomplete.getPlace();
$scope.location = place.geometry.location.lat() + ',' + place.geometry.location.lng();
$scope.$apply();
});
}
}
});
和 HTML:
<div class="form-group enterprise-form">
<label>Full Address</label>
<google-places location=location></google-places>
</div>
我想再填充两个或三个字段lat,lng, postal code。我可以扩展我的指令来实现这一点吗?如果可以,如何实现?
【问题讨论】:
-
你或许应该尝试一下,看看你能走多远,如果遇到困难,再回来问具体问题。
-
你不能要求为你写代码(从头开始),你不会得到任何答案,因为这不是一个问题。
-
好的,谢谢.. 我刚刚在上面添加了我的代码,通过它我只能得到地址。但我想代表地址多一些东西。