我使用的是棱角分明谷歌商家信息自动填充API由AGM提供。它的伟大工程,但我有麻烦的手动设置我的起始位置。也就是说,如果我坐在我在洛杉矶的电脑,我想告诉API,好像我是在波士顿返回结果的能力。我相信这是可能在谷歌的最后,基于their documentation,但我还没有想出如何我使用的角度成分的范围内做到这一点。
任何人有关于如何得到这个工作小费了吗?下面是我的组件的相关部分。谢谢!
setGoogleMapsAutocomplete() {
this.mapsAPILoader.load().then(() => {
let autocomplete = new google.maps.places.Autocomplete(this.searchElementRef.nativeElement, {
types: ["address"]
});
autocomplete.addListener("place_changed", () => {
this.ngZone.run(() => {
let place = autocomplete.getPlace();
this.address = '';
for (var i = 0; i < place.address_components.length; i++)
{
var addressType = place.address_components[i].types[0];
if (this.hasOwnProperty(addressType)) {
let nameLength = addressType == 'administrative_area_level_1' ? 'short_name' : 'long_name';
this[addressType] = place.address_components[i][nameLength];
}
}
this.error = false;
});
});
});
}
显然,你已经使用的代码从这个例子https://brianflove.com/2016/10/18/angular-2-google-maps-places-autocomplete/
你有没有尝试添加location
键,并通过lat,lon
的价值你传递的第二个参数google.maps.places.Autocomplete
的对象。因此,它应该是这样的:
let autocomplete = new google.maps.places.Autocomplete(this.searchElementRef.nativeElement, {
types: ["address"],
radius: 50000,
location: `${this.latitude}, ${this.longitude}`
});
我创建了一个stackblitz沙箱为您https://stackblitz.com/edit/angular-google-maps-demo-qwrngk
随意玩,但不要忘记更改API密钥,因为我的名额似乎被超过。
UPDATE
您还需要设置内要返回的地方结果radius
。