[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.
Hope this helps those who are looking for the ways to use computeArea() without resolving to ugly/complex self-created methods. :)
Here's the snippet of the code I found on stackoverflow.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}; |
Hope this helps those who are looking for the ways to use computeArea() without resolving to ugly/complex self-created methods. :)
Comments
Post a Comment