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 8512015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:09:58+00:00 2026-06-11T04:09:58+00:00

I have a problem with a map on which I’ve used the fitBounds map

  • 0

I have a problem with a map on which I’ve used the fitBounds map methods, which should give the proper zoom and center the map giving it a latlon array. here’s the code:

<script type="text/javascript"
    src="http://maps.googleapis.com/maps/api/js?sensor=false">
</script>


<div id="map_canvas">

<script type="text/javascript">
    var map;
    var bounds = new google.maps.LatLngBounds(null);

    function initialize() {
        var mapOptions = {       

            mapTypeId: google.maps.MapTypeId.ROADMAP
        };

        map =  new google.maps.Map(document.getElementById("map_canvas"), mapOptions);



        <?php
        foreach ($this->getProductCollection() as $_e):
            $event = Mage::getModel('catalog/product')->load($_e->getId());
            ?>
                var loc = new google.maps.LatLng("<?php echo $event->getEventLocationLatitude(); ?>","<?php echo $event->getEventLocationLongitude(); ?>");
                 bounds.extend(loc);
                addMarker(loc, '<?php echo $event->getName(); ?>', "active");
                bounds.extend(loc);

        <?php endforeach; ?>


        map.fitBounds(bounds);
        map.panToBounds(bounds);


    }


function addMarker(location, name, active) {          
    var marker = new google.maps.Marker({
        position: location,
        map: map,
        title: name,
        status: active
    });

}



jQuery.noConflict();

jQuery(document).ready(function(){
    initialize();
});
</script>

The markers are correctly placed on the map, but I get the maximum zoom available:

enter image description here

Any help?

  • 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-06-11T04:09:59+00:00Added an answer on June 11, 2026 at 4:09 am

    I’ve updated your fiddle here: http://jsfiddle.net/KwayW/1/

    It works now as expected.

    Here’s the full code (save this as test.html and open in browser):

    <style>#map_canvas { width:500px; height: 400px; }</style>
    <script src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
    
    <div id="map_canvas"></div>
    
    <script>
    var map;
    var markersArray = [];
    var image = 'img/';
    var bounds = new google.maps.LatLngBounds();
    var loc;
    
    function init(){
        var mapOptions = { mapTypeId: google.maps.MapTypeId.ROADMAP };
        map =  new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
    
        loc = new google.maps.LatLng("45.478294","9.123949");
        bounds.extend(loc);
        addMarker(loc, 'Event A', "active");
    
        loc = new google.maps.LatLng("50.83417876788752","4.298325777053833");
        bounds.extend(loc);
        addMarker(loc, 'Event B', "active");
    
        loc = new google.maps.LatLng("41.3887035","2.1807378");
        bounds.extend(loc);
        addMarker(loc, 'Event C', "active");
    
        map.fitBounds(bounds);
        map.panToBounds(bounds);    
    }
    
    function addMarker(location, name, active) {          
        var marker = new google.maps.Marker({
            position: location,
            map: map,
            title: name,
            status: active
        });
    }
    
    $(function(){ init(); });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem with google map Loading and making center in my java script
Hey people, i have a the following map* which is giving me lots of
I have a problem adding to a variable which is a map in velocity
I have a problem with the operator<() method which is required for a std::map.
I have a problem with Map objects, while using Gravity. All messages works ok,
I just started working with Android and I have a problem with my map.
I have a very basic texture map problem in GL on iPhone, and I'm
I have a problem creating a std::map<int, int> from a vector of pointers, called
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I have a problem that I can't resolve. Let's say I have this map

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.