参见 Google 地图官方文档(下面的链接),因为他们在简单/简单的地图上解决了国家/地区距离问题:)
我推荐这个解决方案来轻松/简单地解决边界问题,您可以知道您正在解决哪个区域的边界问题(不推荐在全球范围内)
注意:
纬线从西向东延伸,标记一个点的南北位置。纬线称为平行线,总共有 180 度的纬度。每个纬度之间的距离约为 69 英里(110 公里)。
距离赤道越远,经度之间的距离越小。赤道经度之间的距离与纬度相同,大约为 69 英里(110 公里)。在北纬 45 度或南纬 45 度处,两者之间的距离约为 49 英里(79 公里)。当子午线在该点汇聚时,两极的经度之间的距离为零。
Original source 1
Original source 2
Official Google Maps Documentation: Code Example: Autocomplete Restricted to Multiple Countries
查看他们的代码部分,他们如何解决距离中心 + 10 公里 +/- 0.1 度的问题
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 };
// Create a bounding box with sides ~10km away from the center point
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"],
};