The Mobile Galaxy The New Mobile Era Has Come | Mobile – A Time To Remember


Send Google Static map with direction in mail



I was working one with project in which client needed to send Google Static Map image with direction to email, After search for few hours i found one script which showed how to get static map for origin to destination but script did not have option for having multiple address as destinations. So i started digging more about Google Direction API, which is fantastic.

Google Direction API –

Google Direction API can give you direction between 2 points (Only if there no sea in between. ;) If there is sea in between, we need to find AIR Direction API) in asked formats. Supported formats ar JSON, XML.

Detail about how to use Google Direction API is shown at Google.

After getting response from Google Direction API in JSON, we can parse it and extract direction steps and polyline points which helps draw line in Google Map.

For showing Static Map please refer to Google Static Map API –



getmap("Vadodara", array("Vallabh Vidya Nagar, Anand, Gujarat, India", "bareja, gujarat, India"));

 * Implementation of hook_form().
function getmap($strStartAddress, $arrAddressInOrder) {
    global $base_url;

    $markers = array();

    $arrLatLon = getLatLong($strStartAddress);
    $markers[] = $arrLatLon['lat'].",".$arrLatLon['long'];

    foreach($arrAddressInOrder AS $address) {

        $arrLatLon = getLatLong($address);
        $markers[] = $arrLatLon['lat'].",".$arrLatLon['long'];

    /* Get the driving directions from google api */
    $directions = retrieveDirections($strStartAddress, $arrAddressInOrder);

    /* Create the map image url with the directions coordinates */
    $staticMap = buildStaticMap($markers, 640, 640, $directions);

    $img = "<img src='$staticMap' align='left'/>";

    $instruction = "<p>Driving instruction displayed below.</p>";
    $legIndex = 0;
    foreach($directions['routes'][0]['legs'] AS $leg) {
        $instruction .= "<p><strong>".$leg['start_address']."</strong><p>";
        foreach($leg AS $steps) {
            if(!is_array($steps)) continue;
            foreach($steps AS $step) {
                if(!is_array($step)) continue;
                $instruction .= $step['html_instructions']."<br />";
        if($legIndex == (count($directions['routes'][0]['legs']) - 1))
            $instruction .= "<p><strong>".$leg['end_address']."</strong><p>";

    echo '<p>'.$img.$instruction.'</p>';


function getLatLong($address){
    if (!is_string($address))die("All Addresses must be passed as a string");
    $_url = sprintf('',rawurlencode($address));
    $_result = false;
    if($_result = file_get_contents($_url)) {
        if(strpos($_result,'errortips') > 1 || strpos($_result,'Did you mean:') !== false) return false;
        preg_match('!center:\s*{lat:\s*(-?\d+\.\d+),lng:\s*(-?\d+\.\d+)}!U', $_result, $_match);
        $_coords['lat'] = $_match[1];
        $_coords['long'] = $_match[2];
    return $_coords;

function buildStaticMap($markers=array(), $width=400, $height=400, $directions=null) {
    $strMarkers = "";
    foreach($markers as $marker) {
        if (!empty($strMarkers)) $strMarkers .= '|';
        $strMarkers .= urlencode($marker);

    if (!empty($directions)) {
        $steps .= $directions['routes'][0]['overview_polyline']['points'];

    if($strMarkers != "")
        $strMarkers = "&markers=".$strMarkers;

    $staticMap = ''.$width.'x'.$height.'&maptype=roadmap&sensor=false' .$strMarkers. '&path=weight:3|color:blue|enc:'.$steps;
    return $staticMap;

function retrieveDirections ($from, $arrTo) {

    $q = "origin=".urlencode($from)."&";

    $q .= "destination=".urlencode($arrTo[count($arrTo) - 1])."";

    $index = 0;
    foreach($arrTo AS $index => $value) {
        if($index == (count($arrTo) - 1)) break;
        $via[] = urlencode($value);

    if(count($via) > 0)
        $q = $q."&waypoints=".(implode("|", $via));

    $url = "". $q;
    $result = file_get_contents($url);
    $result = json_decode($result, true);

    return $result;

Running DEMO

Tagged as: , 2 Comments

Today, InMotion Hosting was hacked

Today, My website was hacked. A message show all InMotion servers were hacked. I just moved to InMotion Hosting because of Rank #1,  before I had rent three different web hosting, all never occurred to be hacked. Sad.


index.php pages were replaced or added to folders. Simply restoring from a backup should fix the problem. If you don’t have a backup and if you have un-modified index.php from wordpress or oscommerce you can just overwrite download that version of software you’re running and overwrite the index.php they put in.

How to fix Inmotion Hosting hack by Tiger M@te




Servers of InMotion Hosting have been hacked. The home page of InMotion Hosting is showing hacked, though some of the internal website pages are working fine.

Update 25-Sept, 4.45 AM CST: I was able to get in touch with the support team of Inmotion Hosting, and got this info:

there appears to be a mass server hack that has replaced the index file in the public_html of several accounts, we are working to do a full server restore on all servers to get that back up and running, unfortunately as there is an investigation going on now my details given to me are limited

Update 25-Sept, 5.02 AM CST: Many customers of InMotion Hosting have mentioned in comments below that it is easy to get your hacked website back up. If you have some old Index.php file, just copy that to the existing Index.php, and your website will probably be back up. This is because hackers seem to have replaced Index.php files on many accounts (InMotion support team also confirmed that above). I am trying this right now.

Update 25-Sept, 5.15 AM CST: Home Page of InMotion Hosting has been restored. Still no word from management on when will they restored the affected websites of customers, and how did this large scale hack happened.

I have a couple of websites with InMotion Hosting, and they are also showing the same “Hacked” page.

There is no official word yet from InMotion Hosting on the extent of hack, and time it will take for websites to get back up.

What worries me most is that hackers might steal the credit card info that InMotion hosting would have stored. Also, I am really hoping that InMotion Hosting is able to get my websites back up, with all the data, and I don’t end up losing everything.

Tagged as: , 1 Comment

Google API for coordinate to address

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<META content="text/html; charset=utf-8" http-equiv=content-type>
<html xmlns="" >
<script src=""
<script type="text/javascript">
var geocoder = null;
function addAddressToMap(response) {
   if (!response || response.Status.code != 200) {
   } else {

    var add="";
    for(var i=0;i<response.Placemark.length;i++)
    add+=response.Placemark[i].address+" | ";
    alert("您查找的位置是 : " + add);

function showLocation(address) {

   if (GBrowserIsCompatible()) {
    geocoder = new GClientGeocoder();
    geocoder.getLocations(address, addAddressToMap);


<a href="javascript:void(0)"
     onclick="showLocation('22.567610,113.864749');return false;">
     取得地址 </a>


该校正适用于 Google map China, Microsoft map china ,MapABC 等,因为这些地图构成方法是一样的。

需要offset.dat文件,该文件为0.01精度校正数据, 有需要者请联系作者, 报价: 5,000.00 RMB。


header("Content-Type:text/html; charset=utf-8");
define('__dat_db__' , 'offset.dat' );// DAT数据文件
define('datmax' , 9813675 );// 数据条数-结束记录

// # offset.php?lat=39.914914&lon=116.460633
$tmplon=intval($lon * 100);
$tmplat=intval($lat * 100);
function lngToPixel($lng,$zoom) {
return ($lng+180)*(256<<$zoom)/360;
function pixelToLng($pixelX,$zoom){
return $pixelX*360/(256<<$zoom)-180;
function latToPixel($lat, $zoom) {
$siny = sin($lat * pi() / 180);
return (128<<$zoom)*(1-$y/(2*pi()));
function pixelToLat($pixelY, $zoom) {
$y = 2*pi()*(1-$pixelY /(128 << $zoom));
$z = pow(M_E, $y);
$siny = ($z -1)/($z +1);
return asin($siny) * 180/pi();

function xy_fk( $number ){
        $fp = fopen(__dat_db__,"rb"); //■1■.将 r 改为 rb
        $left = 0;//开始记录
        $right = datmax;//结束记录

        while($left <= $right){
            $recordCount =(floor(($left+$right)/2))*8; //取半
            //echo "运算:left=".$left." right=".$right." midde=".$recordCount."<br />";
            @fseek ( $fp, $recordCount , SEEK_SET ); //设置游标
            $c = fread($fp,8); //读8字节
            $lon = unpack('s',substr($c,0,2));
            $lat = unpack('s',substr($c,2,2));
            $x = unpack('s',substr($c,4,2));
            $y = unpack('s',substr($c,6,2));
            //echo "找到的经纬度:".$jwd;
            if ($jwd==$myxy){
               return $x[1]."|".$y[1];
            }else if($jwd<$myxy){
               //echo " > ".$myxy."<br />";
               $left=($recordCount/8) +1;
            }else if($jwd>$myxy){
               //echo " < ".$myxy."<br />";
               $right=($recordCount/8) -1;


$offset =xy_fk($tmplon.$tmplat);

echo pixelToLat($latPixel,18).",".pixelToLng($lngPixel,18);



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;   

namespace MapDigit.GIS
    public class GeoLatLng

        public GeoLatLng(double latitude, double longitude)
            this.latitude = latitude;
            this.longitude = longitude;
        public double latitude;
        public double longitude;

    public class GeoPoint
        public GeoPoint(int x, int y)
            this.x = x;
            this.y = y;
        public int x;
        public int y;

    public class OffsetInChina
        public static GeoLatLng fromEarthToMars(GeoLatLng earth)
            GeoPoint ptOffset = getOffset(earth.latitude, earth.longitude);
            if (ptOffset.x != 0 || ptOffset.y != 0)
                int pixelX, pixelY;
                TileSystem.LatLongToPixelXY(earth.latitude, earth.longitude, 18, out pixelX, out pixelY);
                GeoPoint pt = new GeoPoint(pixelX, pixelY);
                pt.x += ptOffset.x;
                pt.y += ptOffset.y;
                double latitude, longitude;
                TileSystem.PixelXYToLatLong(pt.x, pt.y, 18, out latitude, out longitude);
                return new GeoLatLng(latitude, longitude);   

                return new GeoLatLng(earth.latitude, earth.longitude);


        public static GeoLatLng fromMarToEarth(GeoLatLng mars)
            GeoPoint ptOffset = getOffset(mars.latitude, mars.longitude);
            if (ptOffset.x != 0 || ptOffset.y != 0)
                int pixelX, pixelY;
                TileSystem.LatLongToPixelXY(mars.latitude, mars.longitude, 18, out pixelX, out pixelY);
                GeoPoint pt = new GeoPoint(pixelX, pixelY);
                pt.x -= ptOffset.x;
                pt.y -= ptOffset.y;
                double latitude, longitude;
                TileSystem.PixelXYToLatLong(pt.x, pt.y, 18, out latitude, out longitude);
                return new GeoLatLng(latitude, longitude);   

                return new GeoLatLng(mars.latitude, mars.longitude);

        private static GeoPoint getQueryLocation(double latitude, double longitude)
            int lat = (int)(latitude * 100);
            int lng = (int)(longitude * 100);
            double lat1 = ((int)(latitude * 1000 + 0.499999)) / 10.0;
            double lng1 = ((int)(longitude * 1000 + 0.499999)) / 10.0;
            for (double x = longitude; x < longitude + 1; x += 0.5)
                for (double y = latitude; x < latitude + 1; y += 0.5)
                    if (x <= lng1 && lng1 < (x + 0.5) && lat1 >= y && lat1 < (y + 0.5))
                        return new GeoPoint((int)(x + 0.5), (int)(y + 0.5));
            return new GeoPoint(lng, lat);

        private static GeoPoint getOffset(double longitude, double latitude)
            return null;

Tagged as: , 4 Comments