Welcome Guest, Not a member yet? Register   Sign In
Google Maps API 3 : Zoom Extent
#1

[eluser]JamesTaylor[/eluser]
Hi Guys,

first of all sorry that this isn't specifically codeigniter relevant!... but it is within a codeigniter site!

Hopefully there is someone on here who knows their way around google maps APIv3!

I'm trying to get a google map, which is showing some search results of dealerships location on the map using markers which i have achieved. However i would like the map to zoom to the extent of the markers which are being displayed - for example if someone searches dealers near to Liverpool and there are 5 dealers within close proximity the map will show all 5 markers with a tight zoom around the locations, but if someone searches Bradford and the nearest dealers are in Liverpool the map will show the markers but with a wider zoom level - so it shows the location searched and the nearest dealers in Liverpool.

The code I have at present is:

Code:
function initialize() {
                var latlng = new google.maps.LatLng(<?php echo $Lat ?>, <?php echo $Lng ?>);
                var myOptions = {
                  zoom: 10,
                  center: latlng,
                  mapTypeId: google.maps.MapTypeId.ROADMAP
                };
                var map = new google.maps.Map(document.getElementById("MapCanvas"),
                    myOptions);
                
                <?php foreach ($Results as $row): ?>
                    var myLatlng = new google.maps.LatLng(<?php echo $row['Lat'] ?>, <?php echo $row['Lng'] ?>)
                    var marker = new google.maps.Marker({
                    position: myLatlng,
                    title:"<?php echo $row['DealerName'] ?>"
                    });
                    marker.setMap(map);
                <?php endforeach; ?>
}

How can i make it so it zooms the extent of the markers being plotted?

Thanks, James
#2

[eluser]BIOSTALL[/eluser]
Hi James,

I'm not sure if it's of any use but I have made a Google Maps V3 API library for CodeIgniter. The library allows you to achieve exactly what you are after, handling it all for you including adding the markers and doing the automatic zoom.

[email=http://biostall.com/codeigniter-google-maps-v3-api-library]You can download it and view examples here.[/email]

Alternatively if you view some of the demos on the page and click 'View Source' you will see how the automatic zoom is accomplished in the Javascript.

Hope that helps




Theme © iAndrew 2016 - Forum software by © MyBB