Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1023393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:36:42+00:00 2026-05-16T11:36:42+00:00

For some reason the getBounds() function for Google Maps v3 seems to be extending

  • 0

For some reason the getBounds() function for Google Maps v3 seems to be extending much further than what the map is actually showing. Correct me if I’m wrong, but shouldn’t it return the NE (top right corner) and SW (bottom left corner) latitude and longitude coordinates for the very corners of what’s being shown in the current view?

I’m returning search results (which are mapped by a lat and lng) that are between these coordinates and am being returned results much further outside the area returned by getBounds(). Any ideas about what could be going on here?

Just FYI, I’m getting the bounds on the map’s idle event:

google.maps.event.addListener(map, 'idle', function() {

var bounds = map.getBounds();
var NE = bounds.getNorthEast();
var SW = bounds.getSouthWest();

…and using .lat() and .lng() to get the coordinates from the respective corners. Then I feed that to a SQL query that checks for results between those coordinates. Results are in the general area but can fall far outside what’s actually being shown on the map.

Any ideas are appreciated! Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:36:43+00:00Added an answer on May 16, 2026 at 11:36 am

    Correct, the map.getBounds() will return the bounds of the viewable area, as shown in the example below. In this example, a red Polyline box is drawn using the points of map.getBounds() when the idle event fires.

    Your SQL query might not be returning the results you are looking for, and may need looked at again.

    <!DOCTYPE html>
    <html>
    <head>
    <title>Bounds Box</title>
    <script type="text/javascript"
        src="http://maps.google.com/maps/api/js?sensor=false">
    </script>
    <script type="text/javascript">
          function initialize() {
    
            var latlng = new google.maps.LatLng(30.405865,-87.283362);
            var myOptions = {
              zoom: 8,
              center: latlng,
              mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            var map = new google.maps.Map(document.getElementById("map_canvas"),
                myOptions);
            var viewportBox;
    
            google.maps.event.addListener(map, 'idle', function(event) {
                var bounds = map.getBounds();
    
                var ne = bounds.getNorthEast();
                var sw = bounds.getSouthWest();
    
                var viewportPoints = [
                    ne, new google.maps.LatLng(ne.lat(), sw.lng()),
                    sw, new google.maps.LatLng(sw.lat(), ne.lng()), ne
                ];
                /*strokeOpacity = 0 , if don't want to show the border moving. */
                if (viewportBox) {
                    viewportBox.setPath(viewportPoints);
                } else {
                    viewportBox = new google.maps.Polyline({
                        path: viewportPoints,
                        strokeColor: '#FF0000',
                        strokeOpacity: 1.0,
                        strokeWeight: 4 
                    });
                    viewportBox.setMap(map);
                };
    
                var info = document.getElementById('info');
                info.innerHTML = 'NorthEast: ' + ne.lat() + '   ' + ne.lng() + 
                    '<br />' + 'SouthWest: ' + sw.lat() + '   ' + sw.lng();
            });
          };
    </script>
    </head>
    <body onload="initialize()">
      <div id="map_canvas" style="width:500px; height:500px"></div>
      <div id="info"></div>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, the Google API expects longs instead of objects (like Color). What
For some reason (probably because i don't understand closures) function inResult always returns false
For some reason, exceptions thrown in an __autoload function aren't being caught when trying
For some reason this function is doing something weird just in Firefox function fadeOUT_sect(id)
For some reason, Django seems to be displaying my ImageField URL strings escaped. See
For some reason, after some days working with XCode4, it simply stopped showing the
For some reason I'm getting more results than I expected since the upgrade to
For some reason when I attempt to store boolean data in the Google Apps
For some reason only the save button is showing up on the edit click...not
For some reason, this line of code is returning undefined for $(this).attr(href) $(a).attr(href, javascript:page('

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.