It took time to find that function to me (I dont remember the source). It
could certainly be added to the API set.
function llr_to_bounds ( lat, lng, distance )
{
// angular distance in radians on a great circle
var radius = 6371000
, radDist = distance / radius
, radLat = to_rad( lat )
, radLon = to_rad( lng )
, minLat = radLat - radDist
, maxLat = radLat + radDist
, minLon
, maxLon
, MIN_LAT = -Math.PI/2
, MAX_LAT = Math.PI/2
, MIN_LON = -Math.PI
, MAX_LON = Math.PI ;
if ( minLat > MIN_LAT && maxLat < MAX_LAT )
{
var deltaLon = Math.asin( Math.sin( radDist ) / Math.cos( radLat ) )
;
minLon = radLon - deltaLon;
maxLon = radLon + deltaLon;
if ( minLon < MIN_LON ) minLon += 2 * Math.PI ;
if ( maxLon > MAX_LON ) maxLon -= 2 * Math.PI ;
}
else
{
// a pole is within the distance
minLat = Math.max( minLat, MIN_LAT ) ;
maxLat = Math.min( maxLat, MAX_LAT ) ;
minLon = MIN_LON ;
maxLon = MAX_LON ;
}
return new google.maps.LatLngBounds( new google.maps.LatLng( to_deg(
minLat ), to_deg( minLon ) )
, new google.maps.LatLng( to_deg(
maxLat ), to_deg( maxLon ) ) ) ;
}
--
You received this message because you are subscribed to the Google Groups
"Google Maps JavaScript API v3" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-maps-js-api-v3/-/2_m9LHNmq1UJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-js-api-v3?hl=en.