google maps api example class in php - display static google maps
google-maps-api-example-class.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>google maps api example class in php - display static google maps</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Md Iqbal Hosan">
<meta name="title" content="google maps api example class in php - display static google maps">
<meta name="keywords" content="php, example, code, class, function, static google maps, google maps, google maps class">
<meta name="description" content="google maps api example class in php - display static google maps">
<style>
h2, h3{background:#ccc; color:#000082;}
h2{ padding:3px; margin:3px; font-size:20px;}
h3{ padding:2px; margin:2px; font-size:16px;}
p{ padding:3px; margin:3px;}
body{ background:#FFFFFa;}
</style>
</head>
<body>
<h2>google maps api example class in php - display static google maps</h2>
<pre>
<?php
/*
-----------------------------------------------------------------------------------------
let us make the class
where
1. location will be given dynamically
2. size of the static maps width*height
3. apiKey is the key can be found from http://code.google.com/apis/maps/signup.html
* in production server you must have to provide an api key
unless otherwise maps will not be shown.
-----------------------------------------------------------------------------------------
*/
class GoogleStaticMap
{
var $location;
var $size = "300x300";
var $apiKey = "ABQIAAAAja8737JPPkGXnX7f0nXhqBSBI8j0gOhjQo7uwdgX3PTCbPtdhRTXoFrSSb5p3QJLrwF-w4t3d8E6Xg";
function GoogleStaticMap($location)
{
$this->location = $location;
}
function DisplayMap()
{
return "<img src='http://maps.google.com/maps/api/staticmap?center={$this->location}&size={$this->size}&sensor=false&key={$this->size}' alt='{$this->apiKey}'>";
}
}
/*
--------------------------------------------------------------------------------------
now we want to fire up the class to make object to display google maps
--------------------------------------------------------------------------------------
*/
$location = "dhaka,BD";
echo "<h3>parameter supplied to class to make the maps</h3>";
print "<p>$"."location = ".$location."</p>";
$Map = new GoogleStaticMap($location);
echo $Map->DisplayMap();
/*
--------------------------------------------------------------------------------------
you can dynamically change the value of $location to get the desire google maps
--------------------------------------------------------------------------------------
*/
?>
</pre>
</body>
</html>

No comments:
Post a Comment
leave your comments here..