简体   繁体   中英

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()

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.

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

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.

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

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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