请参考官方谷歌地图文档(下面链接)解决关于不同国家之间距离的问题 :)
我推荐这种简单易行的方法来解决边界问题,你可以知道正在解决哪个区域的边界问题(不建议全局使用)
注意:
纬线由西向东延伸并标记点的南北位置。纬线称为平行线,总共有180度纬线。每条纬线之间的距离约为69英里(110公里)。
经线之间的距离随着距赤道越远而变窄。赤道上经线之间的距离与纬度相同,大约为69英里(110公里)。在北纬或南纬45度时,经线之间的距离约为49英里(79公里)。在极点处,经线之间的距离为零,因为子午线在该点汇聚。
原始来源1
原始来源2
![在此输入图像描述](https://istack.dev59.com/1ezC2.webp)
官方谷歌地图文档:代码示例:仅限多个国家的自动完成
看一下他们的代码部分,他们是如何通过 +/- 0.1 度解决以中心距离 +10 公里的问题
function initMap(): void {
const map = new google.maps.Map(
document.getElementById("map") as HTMLElement,
{
center: { lat: 50.064192, lng: -130.605469 },
zoom: 3,
}
);
const card = document.getElementById("pac-card") as HTMLElement;
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(card);
const center = { lat: 50.064192, lng: -130.605469 };
const defaultBounds = {
north: center.lat + 0.1,
south: center.lat - 0.1,
east: center.lng + 0.1,
west: center.lng - 0.1,
};
const input = document.getElementById("pac-input") as HTMLInputElement;
const options = {
bounds: defaultBounds,
componentRestrictions: { country: "us" },
fields: ["address_components", "geometry", "icon", "name"],
origin: center,
strictBounds: false,
types: ["establishment"],
};