Monday, 15 September 2014

Integrating GoogleMap with Multiple Location Markers in Your Website

In your website,Their may arise situation to show multiple locations in your Contact  Google map. May be  you want to show all the branches of the corresponding companies in it.
So In this post I will explain How to do that.

Include this script in your header:-

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script> <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script> <script type="text/javascript">     $(document).ready(function() { initialize(); });
    function initialize() {        var map_options = {            center: new google.maps.LatLng(24.4667,54.3667),            zoom: 13,            mapTypeId: google.maps.MapTypeId.ROADMAP        };
        var google_map = new google.maps.Map(document.getElementById("map_canvas"), map_options);
        var info_window = new google.maps.InfoWindow({            content: 'loading'        });
        var t = [];        var x = [];        var y = [];        var h = [];
//add latitude,longitude of locations here 

        t.push('Location Name 1');        x.push(24.4667);        y.push(54.3667);        h.push('<p><strong>Location Name 1</strong><br/>Address 1</p>');
        t.push('Location Name 2');        x.push(24.4690);        y.push(54.3690);        h.push('<p><strong>Location Name 2</strong><br/>Address 2</p>');
 t.push('Location Name 3');        x.push(24.4700);        y.push(54.3700);        h.push('<p><strong>Location Name 2</strong><br/>Address 2</p>');
 t.push('Location Name 4');        x.push(24.4800);        y.push(54.3800);        h.push('<p><strong>Location Name 2</strong><br/>Address 2</p>');

        var i = 0;        for ( item in t ) {            var m = new google.maps.Marker({                map:       google_map,                animation: google.maps.Animation.DROP,                title:     t[i],                position:  new google.maps.LatLng(x[i],y[i]),                html:      h[i]            });
            google.maps.event.addListener(m, 'click', function() {                info_window.setContent(this.html);                info_window.open(google_map, this);            });            i++;        }    }</script> 

After that  include

<div id="map_canvas" style="width:auto;height:400px;">Google Map</div> 

this above line in the place where you want to show your map.

ENJOY !!!! Have a Great day!!!!

Wednesday, 3 September 2014

Creating Zip file of a folder in PHP

During large php projects , we have to create zip files dynamically. Iam explaining  in this post how to create zip file of a folder dynamicaly using PHP. In PHP we didn't want to  add external libraries for creating zip files. We have ZIPARCHIVE library available in php library itself.

So I will explain step by step in how to acheive this...

1) Create a folder named zip or any name you like in the root directory. This will be the directory which will store the zip files.

2) Create a folder named samplesite & place all the files inside this folder. This folder will be converted to zip file.

3) Create a php page and paste the below code

<?php

$filename="Filename.zip"; // name of the zip file to create

// Adding files to a .zip file, no zip file exists it creates a new ZIP file

// increase script timeout value
ini_set('max_execution_time', 5000);

// create object
$zip = new ZipArchive();

// open archive 
if ($zip->open('zip/'.$filename, ZIPARCHIVE::CREATE) !== TRUE) {
    die ("Could not open archive");
}

// initialize an iterator
// pass it the directory to be processed
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("samplesite/"));
//give the folder name to be zipped

// iterate over the directory
// add each file found to the archive
foreach ($iterator as $key=>$value) {
    $zip->addFile(realpath($key), $key) or die ("ERROR: Could not add file: $key");
}

// close and save archive
$zip->close();
echo "Archive created successfully.";
?>


After Executing this script, check the folder zip, it contains the zip file filename.zip....
Hope this post helps... For any help.. pls let me know...