javascript Google Maps API v3 -- 如何将 .getBounds() 转换为像素坐标?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14655614/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 22:14:58  来源:igfitidea点击:

Google Maps API v3 -- How to convert .getBounds() to to pixel coordinates?

javascriptgoogle-maps-api-3

提问by Josh B

I know how to use an overlay projection to get a LatLng object, and then convert that single LatLng to pixels, using .fromLatLngToDivPixel()

我知道如何使用叠加投影来获取 LatLng 对象,然后使用 .fromLatLngToDivPixel() 将该单个 LatLng 转换为像素

However, .getBounds() returns a pair of LatLng coordinates. I've tried accessing it like it's an array (as in specifying index[1] for example) but that does not work. It doesn't seem to be an array.

但是, .getBounds() 返回一对 LatLng 坐标。我试过像访问数组一样访问它(例如在指定 index[1] 中),但这不起作用。它似乎不是一个数组。

Is there a way to convert the value from .getBounds() to pixel data?

有没有办法将值从 .getBounds() 转换为像素数据?

回答by Marcelo

However, .getBounds() returns a pair of LatLng coordinates. I've tried accessing it like it's an array (as in specifying index1for example) but that does not work. It doesn't seem to be an array.

但是, .getBounds() 返回一对 LatLng 坐标。我试过像访问数组一样访问它(例如在指定索引1 时),但这不起作用。它似乎不是一个数组。

LatLngBounds is not an array, it's an object and the documentationshows you two methods to get the coordinates:

LatLngBounds不是数组,它是一个对象,文档向您展示了两种获取坐标的方法:

var NE = bounds.getNorthEast();
var SW = bounds.getSouthWest();

Those two methods return LatLng objects which you can pass to fromLatLngToDivPixel()However, if you got your LatLngBounds object by reading map.getBounds()then you already know what the pixel values should be, (the corners of your map container DIV).

这两个方法返回 LatLng 对象,您可以将其传递给fromLatLngToDivPixel()但是,如果您通过读取获得 LatLngBounds 对象,map.getBounds()那么您已经知道像素值应该是什么(地图容器 DIV 的角)。