PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Fri Dec 19, 2014 6:53 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Tue Feb 09, 2010 12:07 am 
Offline
Forum Newbie

Joined: Sat Feb 06, 2010 2:49 pm
Posts: 19
After a button is clicked, addresses (which are stored in a PHP array) are displayed on an embedded Google Map on my site. I would like the embedded map to automatically zoom to fit the markers. How would I go about this? Here's the important part of my code (I can post the entire PHP file if necessary):

Syntax: [ Download ] [ Hide ]
 
<script type="text/javascript">
   
    var map = null;
    var geocoder = null;
    var latlngbounds = new GLatLngBounds(  );
 
    function initialize() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        <?php if(!isset($_POST['viewed'])){
        echo 'map.setCenter(new GLatLng(36.879621, -95.537109), 2);';}
        else
            {
            echo 'function fitMap( GMap2, points ) {
                var bounds = new GLatLngBounds();
                for (var i=0; i< points.length; i++) {
                    bounds.extend(points[i]);
                }
                map.setZoom(map.getBoundsZoomLevel(bounds));
                map.setCenter(bounds.getCenter());
            }'
;
                       
            fitMap();
            }
       
        ?>
       
       
        map.addControl(new GLargeMapControl());
        geocoder = new GClientGeocoder();
      }
    }
 



I'm trying to use this guy's code, but I can't implement it right:
Syntax: [ Download ] [ Hide ]
 
function fitMap( map, points ) {
   var bounds = new GLatLngBounds();
   for (var i=0; i< points.length; i++) {
      bounds.extend(points[i]);
   }
   map.setZoom(map.getBoundsZoomLevel(bounds));
   map.setCenter(bounds.getCenter());
}
 

From http://blog.jeromeparadis.com/archive/2007/02/08/1468.aspx


I'm fairly well-versed with PHP, but Java is very new to me. Sorry for the long post, but I'd appreciate any help.


[EDIT: SOLVED]

I fixed this using this code: http://econym.org.uk/gmap/basic14.htm

I also changed
Syntax: [ Download ] [ Hide ]
var latlngbounds = new GLatLngBounds(  );
to
Syntax: [ Download ] [ Hide ]
var bounds = new GLatLngBounds(  );


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group