Follow Me

Google map demo using php class

Wed, Jun 9, 2010

PHP

Hi Guys,

Today I am posting google map demo using php api. Few months back I need to develop a google map in php for my client therefore I google and found some complex methods of generating google map.  There was some script that needs latitude, longitude for gmap. All I wanted to do is to generate google map with address only.  Finally I found a php class that have the simple solution.

There is some simple methods that you need to call by  object of map class.

1. $map->setAPIKey(YOUR Google Map Key);

2. $map->addMarkerByAddress(YOUR Address);

3. $map->printHeaderJS();

4. $map->printMapJS();

Above two methods you need to call within <head></head> tag.

5.  onLoad=”onLoad()”

This method you need to call on <body> tag onload.

6. $map->printMap();

This method display google map. Use it where you want to print google map on your web page.

You can get your gmap key from here.

You can download google map class from here.

Click here for Demo of this script.


<?php
 require_once('GoogleMapAPI.class.php');
 $map = new GoogleMapAPI('map');
 // enter YOUR Google Map Key
 $map->setAPIKey('YOUR Google map key');

 // create map markers which  indicate your location
 $map->addMarkerByAddress('YOUR Complete Address');
?>
<head>
<?php $map->printHeaderJS(); ?>
<?php $map->printMapJS(); ?>
</head>
<body onLoad="onLoad()">
<div style="width:600px; height:400px; border:1px solid #000000;">
<?php $map->printMap(); ?>
</div>
</body>

I hope this tutorial help to learn gmap implementation smartly :) also share your experience with this class or the Google Maps API.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • blogmarks
  • Design Float
  • DZone
  • MySpace
  • Reddit
  • StumbleUpon
  • Twitter
, , , , , , , , ,

Related Posts:


Recent Posts:

  • Best collection of firefox addons for web designers and developers
  • .htaccess basic features with example
  • how to include an external css and js with javascript dynamically
  • How to preserve line breaks in textarea mysql data
  • how to generate excel report with php and mysql
  • Leave a Reply