Posts Tagged ‘js’

Google Maps with PHP and Javascript

Posted: January 31, 2011 in Javascript, PHP5
Tags: ,

<?php

class GoogleMaps
{

var $APIKey = “ABQIAAAASTe3RGQOzgfE_7pgalxCWxTxwC-FTRouMUU4URT3KGgoa5PSihROzcGmVudxV_XFjm17uSpKPwoCYw”;

function SetLocation($Location)
{
$this->Location = $Location;
}
function SetWidth($Width)
{
$this->Width = $Width;
}
function SetHeight($Height)
{
$this->Height = $Height;
}
function DisplayGoogleMaps()
{
?>
<script src=”http://maps.google.com/maps?file=api&v=2&sensor=false&key=&lt;?php echo $this->APIKey; ?>” type=”text/javascript”></script>
<script type=”text/javascript”>
//var JobLocationInGoogleMaps = ‘Dhaka, BD’;
var JobLocationInGoogleMaps = ‘<?php echo $this->Location; ?>’;
if (GBrowserIsCompatible())
{
var geocoder = new GClientGeocoder();
geocoder.getLocations(JobLocationInGoogleMaps, function (locations)
{
if (locations.Placemark)
{
var north = locations.Placemark[0].ExtendedData.LatLonBox.north;
var south = locations.Placemark[0].ExtendedData.LatLonBox.south;
var east = locations.Placemark[0].ExtendedData.LatLonBox.east;
var west = locations.Placemark[0].ExtendedData.LatLonBox.west;

var bounds = new GLatLngBounds(new GLatLng(south, west), new GLatLng(north, east));
var map = new GMap2(document.getElementById(“GoogleMapCanvasHere”));
map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
//map.addControl(new GSmallMapControl());
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addOverlay(new GMarker(bounds.getCenter()));
}
});
}
GUnload();
</script>
<div id=”GoogleMapCanvasHere” style=”width:<?php echo $this->Width; ?>px; height:<?php echo $this->Height; ?>px; background: url(./images/google-maps-loading.gif); background-repeat:no-repeat; background-position:center;”></div>
<?php
}
}

$maps = new GoogleMaps();
$maps->SetLocation(“Khulna,bd”); // Change Location
$maps->SetWidth(500); // Chaneg Map Width
$maps->SetHeight(350); // Change Map Height
$maps->DisplayGoogleMaps();

?>