1 / 15
文档名称:

geohash算法的php,python,java,Csharp版本源码php.doc

格式:doc   大小:40KB   页数:15页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

geohash算法的php,python,java,Csharp版本源码php.doc

上传人:学习的一点 2021/7/25 文件大小:40 KB

下载得到文件列表

geohash算法的php,python,java,Csharp版本源码php.doc

文档介绍

文档介绍:geohash算法的php,python,java,Csharp版本源码php

<?php
/**
* Geohash generation class
* /
*
* This file copyright (C) 2008 Paul Dixon (******@)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*//**
* Encode and decode geohashes
*
*/
class Geohash
{
private $coding="0123456789bcdefghjkmnpqrstuvwxyz";
private $codingMap=array();

public function Geohash()
{
//build map from encoding char to 0 padded bitfield
for($i=0; $i<32; $i++)
{
$this->codingMap[substr($this->coding,$i,1)]=str_pad(decbin($i), 5, "0", STR_PAD_LEFT);
}

}

/**
* Decode a geohash and return an array with decimal lat,long in it
*/
public function decode($hash)
{
//decode hash into binary string
$binary="";
$hl=strlen($hash);
for($i=0; $i<$hl; $i++)
{
$binary.=$this->codingMap[substr($hash,$i,1)];
}

//split the binary into lat and log binary strings
$bl=strlen($binary);
$blat="";
$blong="";
for ($i=0; $i<$bl; $i++)
{
if ($i%2)
$blat=$($binary,$i,1);