最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin4浏览0评论

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?

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?

Share Improve this question asked Feb 1, 2013 at 21:49 Josh BJosh B 1531 gold badge1 silver badge9 bronze badges 9
  • And you didn't found informations about what getBounds() returns and how to access the properties? – Dr.Molle Commented Feb 1, 2013 at 21:55
  • 1 Refrain from being a smartass when talking to me. developers.google./maps/documentation/javascript/… Did you find that information? – Josh B Commented Feb 1, 2013 at 21:58
  • of course, I can't imagine how anyone couldn't find it – Dr.Molle Commented Feb 1, 2013 at 22:02
  • 1 It's so much more polite and reputable of you to point it out to me, considering that you can tell that I am unable to find it, rather than passive aggressively call me an idiot and not assist me in finding it at all. – Josh B Commented Feb 1, 2013 at 22:04
  • 1 I was not asking for "the value" of a LatLngBounds object. If you had read my question with any sort of care, you would notice I was referring to the value that is returned from .getBounds(). Your attitude towards answering my question straightly from the beginning is what is rude. Don't even try and flip the script. You know exactly what you are doing here. – Josh B Commented Feb 1, 2013 at 22:41
 |  Show 4 more ments

1 Answer 1

Reset to default 12

However, .getBounds() returns a pair of LatLng coordinates. I've tried accessing it like it's an array (as in specifying index1 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).

发布评论

评论列表(0)

  1. 暂无评论