如何根据经纬度坐标获得墨卡托原理计算的格子编号?

已邀请:

zkbhj - 凯冰科技站长

赞同来自:

<?php

function getPositionByMercator($mercator, $scale) {
return [floor($mercator[0]/$scale), floor($mercator[1]/$scale)];
}

function getIndexByMercator(array $mercator, $scale){
$pos = getPositionByMercator($mercator, $scale);
return ($pos[0]<<24)+$pos[1];
}

function getMercatorByLngLat(array $lngLat) {
$PI = pi();
$x = number_format ($lngLat[0]*20037508.34/180,6, '.', '');
$y = log(tan((90+$lngLat[1])*$PI/360))/($PI/180);
$y = number_format($y*20037508.34/180, 6, '.', '');

return [$x, $y];
}

function getIndexByLngLat(array $lngLat, $scale) {

return getIndexByMercator(getMercatorByLngLat($lngLat), $scale);
}


$location = [117.279336,39.083255];

$cellid = getIndexByLngLat($location, 200);

//1095166352500
echo $cellid;

?>

要回复问题请先登录注册