Wednesday 30 September 2015

get distance between two address through google api in php

<?php
function get_distance($address1,$address2)
{
$address1_encode = urlencode($address1);
$address2_encode = urlencode($address2);
$addresses_string = "?origins=".$address1_encode."&destinations=".$address2_encode."&key=AIzaSyBf6kfop46PNbRUAG-VwHVrGlyvNunpw9o";
    $url = "https://maps.googleapis.com/maps/api/distancematrix/json".$addresses_string;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    $response = curl_exec($ch);
    curl_close($ch);
   
  return $response;
    //$status = $response_a->status;
}
if(isset($_POST['get_dis'])){
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$results = get_distance($address1,$address2);
$response_a = json_decode($results);

echo "status :- ";
echo $result_status = $response_a->status;
echo "<br/>";
echo "distance :- ";
echo  $distance = $response_a->rows[0]->elements[0]->distance->value;
echo " M";
}
 ?>
 <form action="" method="post">
 <input type="text" name="address1">&nbsp;&nbsp;&nbsp;
 <input type="text" name="address2">&nbsp;&nbsp;&nbsp;
 <input type="submit" name="get_dis" value="Get Distance">

 </form>

Monday 28 September 2015

javascript add class step by step in loop.

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script>
$(function () {
  var $anchors = $('.anchor');

  (function _loop(idx) {
    $anchors.removeClass('highlight').eq(idx).addClass('highlight');
    setTimeout(function () {
      _loop((idx + 1) % $anchors.length);
    }, 2000);
  }(0));
});
</script>
<style>
.highlight{
color:#FF0000;
font-size:24px;
}
</style>
<a class="anchor">A</a>
<a class="anchor">B</a>
<a class="anchor">C</a>
<a class="anchor">D</a>
<a class="anchor">E</a>
<a class="anchor">F</a>
<a class="anchor">G</a>