首页 > 解决方案 > 如何将 HAM Maidenhead Grid Squares 转换为经纬度?

问题描述

在 mySQL 数据库中,我有 HAM 方形格式的点坐标(例如KO03ka)。使用此代码,我得到地理坐标:

// fe user_loc = "KO03ka"

$loc = $user_data['user_loc'];

$lat= 
(ord(substr($loc, 1, 1))-65) * 10 - 90 +
(ord(substr($loc, 3, 1))-48) +
(ord(substr($loc, 5, 1))-65) / 24 + 1/48;
$lng= 
(ord(substr($loc, 0, 1))-65) * 20 - 180 +
(ord(substr($loc, 2, 1))-48) * 2 +
(ord(substr($loc, 4, 1))-65) / 12 + 1/24;

我想使用添加点到地图上print json_encode()。如何正确准备 JSON 文件?在数据库中,我没有 lat、lng,只有方形定位器格式。

$query = mysql_query("select * from maps");

$rows = array();
while($data = mysql_fetch_array($query))
{
    $rows[] = $data;
}

print json_encode($rows);
$db = NULL;

请帮我为 Leaflet 准备 JSON 文件。

标签: phpmysqlleafletcoordinates

解决方案


推荐阅读