Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 386
Josh B Avatar asked Feb 01 '13 21:02

Josh B


People also ask

How do you get latitude from LatLng?

Android: Open Google Maps; it will zoom to your approximate location. Press and hold on the screen to drop a pin marker. Click on the dropped pin; latitude and longitude will be displayed below the map.

What is LatLng in Google map?

A LatLng is a point in geographical coordinates: latitude and longitude. Latitude ranges between -90 and 90 degrees, inclusive.

What is MVCArray?

An MVCArray inherits from MVCObject so you can set or get its properties, bind some of them, be binded by other objects, etc. But also, it implements some extras. It implements several of the methods you could use in a native javascript array, like push , pop , forEach , etc, so several google.


1 Answers

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

like image 78
Marcelo Avatar answered Oct 20 '22 00:10

Marcelo