PHP Classes

GMapBuilder: Present world maps on Web pages using Google Maps

Recommend this page to a friend!
  Info   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStar 54%Total: 2,485 This week: 1All time: 1,551 This week: 560Up
Version License PHP version Categories
gmapbuilder 1GNU General Publi...5PHP 5, Content management, Geography
Description 

Author

This class can be used to present world maps on Web pages using Google maps.

It generates the necessary HTML and Javascript to present the maps of specified locations.

It can set the location of the point in the center of the map and the map zoom level.

The class can also add custom markers that appear on specific locations in the map.

The width, height and additional styles of the map page element can also be configured.

Picture of Steve
Name: Steve <contact>
Classes: 1 package by
Country: United States United States
Age: ???
All time rank: 1253180 in United States United States
Week rank: 416 Up46 in United States United States Up

Details

GMapBuilder - Class for building Google Maps. 1. Author 2. License 3. Description 4. Sites using GMapBuilder 5. Instructions for using GMapBuilder 6. Contact 1. Author Stephen R. MacMinn Version 1.0, November 2006. 2. License GMapBuilder is licensed under the GNU Public License (GPL). http://www.fsf.org/licensing/licenses/gpl.html#SEC4 3. Description The GMapBuilder class handles all the messy details of putting fairly complex Google maps on your web site. GMapBuilder can create Google maps of any size. The maps can have an arbitrary number of markers, each with its own html text block. Maps can also contain polylines or just about any other Google map construct. GMapBuilder uses version 1 of the Google Maps API. 3.1 The Internet Explorer Bug Internet Explorer has a bug which IE cannot manipulate the DOM until the page is fully loaded, when using scripts that create Google maps, this bug may cause the script to fail if the js runs before the map is defined. The only sure way to prevent this is by running the script with the "onload" directive. GMapBuilder works around this bug by encapsulating all of the required javascript in a javascript function called WaitToRun() and running that function from an "onload" directive in the page <body> tag. Instructions for using GMapBuilder are below and are also in the class file itself. IMPORTANT ! Before you can use GMapBuilder, you will need to sign up with Google to obtain a Google Maps API Key. Keys are site specific. In fact, they're directory specific, meaning that a key will only work in site directory for which you registered. You can sign up for an API key here: http://www.google.com/apis/maps/signup.html Google maps require latitude and longitude (geocode) coordinates to map points. For the U.S. there's a geocoding service (translates street address to geocode) at http://geocoder.us . It's free for non-commercial use. 4. Sites using GMapBuilder If you want to see GMapBuilder in action, here are two sites that use it. Placewiki: http://www.placewiki.com. An example of a map with multiple markers is shown at: http://placewiki.com/nearby.php?ref=placeID&placeID=233 PlaceServer: http://stephenmacminn.com/placeserver/index.php PlaceServer is a little demonstration site I built that uses the U.S. Geologic Survey GNIS (Geographic Names Information System) data to map geographic places in the U.S. Try searching for Lake George 5. Instructions for using GMapBuilder A google map consists of four basic elements: 1. The <script> tag that loads the javascript API interface from Google. In GMapBuilder this is getGoogleMapAPIScript(); 2. The <script> that sets up the map and defines points on it. In GMapBuilder this is getWaitToRunScript(); 3. A special <body> tag that keeps all the js from running until after the page has loaded. In GMapBuilder this is getMapBodyTag(); 4. The map container: <div id="map">. In GMapBuilder this is getMapDiv(); To use GMapBuilder: // Instantiate a new GMapBuilder object $GoogleMapAPIKey = "This is where your big long alphanumeric API key from Google goes"; $map = new GMapBuilder($GoogleMapAPIKey); // Define the height and width and zoom level. Height and Width are the size of the map div. $map->setHeight(400); $map->setWidth(300); $map->setZoomLevel(6); // If you want to set styles other than the height and width on the // map div, use setMapDivStyle() to add them. $map->setMapDivStyle("float: right; margin-right: 30px;") // Define the center point of the map $latitude = 45.789; $longitude = -75.324; $map->setCenter($longitude, $latitude); // Add as many markers as you want to the map // Each marker has a geocode (lat/lon) and can have some html that will // appear in a popup when then marker is clicked. $latitude = 42.892; $longitude = -75.221; $html = "<em>This is a point</em>"; $map->addMarker($longitude, $latitude, $html); $latitude = 42.541; $longitude = -75.301; $html = "<em>This is yet another point</em>"; $map->addMarker($longitude, $latitude, $html); // Add any additional javascript as a string. You can use this e.g., to add polylines to the map. $map->addAdditionalJS($jsString) // In the head of the page, output the script that fetches the Google API echo $map->getGoogleMapAPIScript(); // At the end of head of the page, output the <body> tag. // If you have other onload functions, you don't need to use this, but be sure to include // onload = WaitToRun(); in your <body> tag. echo $map->getMapBodyTag(); // At the location on the page where you want the map, output the map div echo $map->getMapDiv(); // Output the "WaitToRun" script that contains the actual javascript that creates the map. echo $map->getWaitToRunScript(); // That's it! 6. Comments and suggestions are welcome: steve at placewiki dot com

  Files folder image Files  
File Role Description
Plain text file GMapBuilder.php Class Class file for GMapBuilder class
Accessible without login Plain text file GmapBuilderDemo.php Example Demo template for using GMapBuilder
Accessible without login Plain text file readme.txt Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
 0%
Total:2,485
This week:1
All time:1,551
This week:560Up
 User Ratings  
 
 All time
Utility:71%StarStarStarStar
Consistency:58%StarStarStar
Documentation:66%StarStarStarStar
Examples:62%StarStarStarStar
Tests:-
Videos:-
Overall:54%StarStarStar
Rank:2039