[Google Maps v3] Get Rectangle area with computeArea

Been searching for ways to calculate rectangle area with google.maps.geometry.spherical.computeArea(), but hard to find.

Here's the snippet of the code I found on stackoverflow.

var _computeRectangleArea = function(bounds) {
if (!bounds) {
return 0;
}
var sw = bounds.getSouthWest();
var ne = bounds.getNorthEast();
var southWest = new google.maps.LatLng(sw.lat(), sw.lng());
var northEast = new google.maps.LatLng(ne.lat(), ne.lng());
var southEast = new google.maps.LatLng(sw.lat(), ne.lng());
var northWest = new google.maps.LatLng(ne.lat(), sw.lng());
return google.maps.geometry.spherical.computeArea([northEast, northWest, southWest, southEast]) / (1000000);
};
view raw gistfile1.txt hosted with ❤ by GitHub


Hope this helps those who are looking for the ways to use computeArea() without resolving to ugly/complex self-created methods. :)

Comments

Popular posts from this blog

[Magento] Create Contact Form with Dynamic Recipient

[Azure Websites PHP] Cross Domain request results in blank response page after Preflight HTTP OPTIONS