PHP Classes

File: ex8.php

Recommend this page to a friend!
  Classes of Vagharshak Tozalakyan   Map Builder   ex8.php   Download  
File: ex8.php
Role: Example script
Content type: text/plain
Description: Example 8 - Filling data from database.
Class: Map Builder
Display maps using Google Maps API v3
Author: By
Last change: Added API key.
Date: 7 years ago
Size: 1,033 bytes
 

Contents

Class file image Download
<?php

// Include MapBuilder class.
require_once 'class.MapBuilder.php';

// Create MapBuilder object.
$map = new MapBuilder();

// Set API key
$map->setApiKey('AIzaSyB230QxSetZoJiM9noon7FiAQXbc-HPSLU');

// Set map's center position by latitude and longitude coordinates.
$map->setCenter(48.860181, 2.3249648);

// Set the default map type.
$map->setMapTypeId(MapBuilder::MAP_TYPE_ID_ROADMAP);

// Set width and height of the map.
$map->setSize(860, 550);

// Set default zoom level.
$map->setZoom(14);

// Connect the database.
mysql_connect('localhost', 'root', '') or die('Unable to connect the database!');
mysql_select_db('map_data') or die('Unable to select the database!');

// Select data and add markers using that data.
$result = mysql_query("SELECT name, lat, lng FROM highlights") or die(mysql_error());
while (
$row = mysql_fetch_assoc($result)) {
   
$map->addMarker($row['lat'], $row['lng'], array(
       
'title' => $row['name']
    ));
}

// Display the map.
$map->show();

?>