我很快就会发疯!我已经阅读了几乎所有的Google Maps JavaScript API V3文档,但是我找不到一种开发以下用例的方法:
我想创建一个以米为单位的方形 /圆 /多边形。圆的半径,或LNG之间的距离。
我知道可以测量与latlngs之间的米距离,但我想创建它的维度。
有没有人知道该怎么做?那真是太神奇了!
I'm going crazy soon! I've read pretty much all of the Google Maps JavaScript API V3 documentation but I can't find a way to develop the following use case:
I want to create a square / circle / polygon with a specific size in meters. The radius of the circle, or the distance between LAT and LNG in meters.
I know it's possible to measure the distance in meters between to LatLngs, but I want to create it wit that dimension.
Is there anybody who know's how to do this? That would be amazing!
发布评论
评论(1)
您可以使用几何库,更具体地说是 方法。
距离
参数为米,尽管从文档中尚不清楚。这是一个使用矩形类的简单示例,但您可以使用任何形状。对于圆圈,您不需要这个,因为半径已经以米为单位表示。
对于矩形,您需要计算范围(
ne
for North-East和sw
西南)。在这里,我创建了一个矩形(在这种情况下为一个正方形),其对角线为500米。对于多边形,您需要提供一条路径而不是边界,但是该方法保持不变。如果您知道每个路径点之间的起点,距离和趋势,则可以提出任何形状。
您需要在API调用中加载几何库:
https://maps.googleapis.com/maps/api/js?libraries= geometry
You can use the Geometry library and more specifically the
computeOffset
method.The
distance
parameter is in meters, although this is not clear from the docs.Here is a simple example using the Rectangle class but you can use any shape. For circles, you don't need this as the radius is already expressed in meters.
For Rectangles, you need to calculate the bounds (
ne
for north-east andsw
for south-west). Here I create a rectangle (a square in this case) with a 500 meters diagonal.For Polygons, you need to provide a path instead of bounds, but the method remains the same. If you know the starting point, the distance and the heading between every path point, you can come up with any kind of shape.
You need to load the Geometry library in the API call:
https://maps.googleapis.com/maps/api/js?libraries=geometry