简体   繁体   English

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

[英]Google Maps API v3 — How to convert .getBounds() to to pixel coordinates?

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. 但是,.getBounds()返回一对LatLng坐标。 I've tried accessing it like it's an array (as in specifying index[1] for example) but that does not work. 我试过访问它就像它是一个数组(例如指定索引[1]),但这不起作用。 It doesn't seem to be an array. 它似乎不是一个数组。

Is there a way to convert the value from .getBounds() to pixel data? 有没有办法将.getBounds()的值转换为像素数据?

However, .getBounds() returns a pair of LatLng coordinates. 但是,.getBounds()返回一对LatLng坐标。 I've tried accessing it like it's an array (as in specifying index 1 for example) but that does not work. 我试过访问它就像它是一个数组(例如在指定索引1 )但这不起作用。 It doesn't seem to be an array. 它似乎不是一个数组。

LatLngBounds is not an array , it's an object and the documentation shows 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()但是,如果你通过读取map.getBounds()获得了LatLngBounds对象,那么你已经知道了像素值应该是什么,(地图容器DIV的角落)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM