从旧的经纬度加上n米计算新的经纬度

153
我希望基于一个坐标和距离(单位为米),创建两个新的经度和两个新的纬度,以便在特定点周围创建一个漂亮的边界框。这是城市的一部分,最大范围为±1500米,因此我认为不需要考虑地球曲率。
所以,给定 50.0452345 (x) 和 4.3242234 (y),我想知道 x + 500 米,x - 500 米,y - 500 米,y + 500 米。
我找到了许多算法,但几乎所有算法似乎都处理点之间的距离。

http://gis.stackexchange.com/questions/25877/how-to-generate-random-locations-nearby-my-location - MilapTank
13个回答

0

这是我在VBA中所做的,似乎对我有效。不过计算单位是英尺而不是米。

Public Function CalcLong(OrigLong As Double, OrigLat As Double, DirLong As String, DirLat As String, DistLong As Double, DistLat As Double)
    Dim FT As Double
    Dim NewLong, NewLat As Double
    FT = 1 / ((2 * WorksheetFunction.Pi / 360) * 20902230.971129)
    
    If DirLong = "W" Then
        NewLat = CalcLat(OrigLong, OrigLat, DirLong, DirLat, DistLong, DistLat)
        NewLong = OrigLong - ((FT * DistLong) / Cos(NewLat * (WorksheetFunction.Pi / 180)))
        CalcLong = NewLong
    Else
        NewLong = OrigLong + ((FT * DistLong) / Math.Cos(CalcLat(OrigLong, OrigLat, DirLong, DirLat, DistLong, DistLat) * (WorksheetFunction.Pi / 180)))
        CalcLong = NewLong
    End If
    
End Function


Public Function CalcLat(OrigLong As Double, OrigLat As Double, DirLong As String, DirLat As String, DistLong As Double, DistLat As Double) As Double
    Dim FT As Double
    Dim NewLat As Double
    
    FT = 1 / ((2 * WorksheetFunction.Pi / 360) * 20902230.971129)
    
    If DirLat = "S" Then
        NewLat = (OrigLat - (FT * DistLat))
        CalcLat = NewLat
    Else
        NewLat = (OrigLat + (FT * DistLat))
        CalcLat = NewLat
    End If
    
End Function


0
请参考官方谷歌地图文档(下面链接)解决关于不同国家之间距离的问题 :)
我推荐这种简单易行的方法来解决边界问题,你可以知道正在解决哪个区域的边界问题(不建议全局使用)
注意:
纬线由西向东延伸并标记点的南北位置。纬线称为平行线,总共有180度纬线。每条纬线之间的距离约为69英里(110公里)。
经线之间的距离随着距赤道越远而变窄。赤道上经线之间的距离与纬度相同,大约为69英里(110公里)。在北纬或南纬45度时,经线之间的距离约为49英里(79公里)。在极点处,经线之间的距离为零,因为子午线在该点汇聚。

原始来源1 原始来源2 在此输入图像描述

官方谷歌地图文档:代码示例:仅限多个国家的自动完成

看一下他们的代码部分,他们是如何通过 +/- 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 };

  // 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"],
  };

0
var meters = 50;
var coef = meters * 0.0000089;
var new_lat = map.getCenter().lat.apply() + coef;
var new_long = map.getCenter().lng.apply() + coef / Math.cos(new_lat * 0.018);
map.setCenter({lat:new_lat, lng:new_long});

3
请在您的回答中添加一些解释。 - Anna
如果您想将地图对象移动大约50米靠近当前地图的中心,则可以使用此代码,并用+,-数字替换+50。 - Eyni Kave

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接