我找了几个星期的信息。 首先,我使用的是AngularJS 1.6和ngMap模块。
这是我正在做的事情:
-
我在主页中使用了搜索框(带有
ngMap
自动完成功能):import htmlTemplate from './searchBox.html'; export default { template: htmlTemplate, require: { parent: '^home' }, controller: function controller(MapsService, $log) { 'ngInject'; const self = this; this.$onInit = () => { $log.info('searchBox component init'); MapsService.loadGoogleApi().then(() => { this.loaded = true; this.onPlaceChanged = function onPlaceChanged() { const place = this.getPlace(); if (place.geometry) { self.activity.lat = place.geometry.location.lat(); self.activity.lng = place.geometry.location.lng(); } }; });
-
另外,我正在使用显示活动的组件。 当我通过表单创建活动时,我填写了一个使用自动完成的地址字段。
<div class="input-field col s12"> <i class="material-icons prefix">location_on</i> <input ng-if="$ctrl.loaded" places-auto-complete ng-model="$ctrl.activity.address" id="icon_prefix" type="text" on-place-changed="$ctrl.onPlaceChanged()" class="validate"> <label for="icon_prefix">{{'ANNOUNCE.ADDRESS' | translate}} </label>
-
我指定地址以纬度/经度转换。
MapsService.loadGoogleApi().then(() => { this.loaded = true; this.onPlaceChanged = function onPlaceChanged() { const place = this.getPlace(); if (place.geometry) { self.activity.lat = place.geometry.location.lat(); self.activity.lng = place.geometry.location.lng(); } }; });
我的问题是:
如何通过使我的搜索框的地址和我的表单地址重合来显示活动(按城市)?
多谢!
所以...我找到了答案。 有必要将存储过程添加到数据库中,并创建一个允许取回数据的函数。