用于将 UTM 坐标转换为纬度和经度的开源 PHP 函数?
我正在制作一个涉及 Google 地图的 PHP 应用程序。地图仅接受 lat&lng 对,并且我要显示的数据仅带有 UTM 样式坐标。是否有开源 PHP 函数可以将一种函数转换为另一种函数?
像这样的事情会很棒:
$UTM_ZONE = '32';
$UTMX = '60329834,34';
$UTMY = '67382984,9';
$latlng = convert($UTM_ZONE, $UTMX, $UTMY);
// $latlng = now looks like
// array('lat' => '59.4472917501', 'lng' => '5.3928572425')
I'm making a PHP application involving Google Maps. Maps only accepts lat&lng pairs, and the data I want to display comes only with UTM style coordinates. Is there an open-source PHP function to convert from one to the other?
Something like this would be great:
$UTM_ZONE = '32';
$UTMX = '60329834,34';
$UTMY = '67382984,9';
$latlng = convert($UTM_ZONE, $UTMX, $UTMY);
// $latlng = now looks like
// array('lat' => '59.4472917501', 'lng' => '5.3928572425')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我发现了一个肮脏的类可以完成这项工作。我所说的“脏”是指函数名称很奇怪,代码的格式也不是很漂亮,但它确实可以完成这项工作。
我一定会更新这个答案,如果我找到更好的课程
I've found sort of a dirty class that does the job. By dirty I mean that the function names are wonky and the code isn't very prettily formatted, but it does indeed do the job.
I'll be sure to update this answer if I find any better classes
这是 PHP 代码,非常感谢,效果很好!
Here is the code in PHP, thanks a lot, works nice !
我知道回答这个问题已经晚了,但由于我无法使用上述任何代码,所以我编写了自己的版本,实际上非常易于使用。
这是地址:
将 UTM 转换为 LatLong:
输出:
将 LatLong 转换为 UTM:
输出:
希望有帮助。
I know it's late to answer this question but since I couldn't use any of the above codes, I wrote my own version which is actually very easy to use.
This is the address:
https://github.com/maroofi/coordinates
To convert UTM to LatLong:
output:
To convert LatLong to UTM:
output:
Hope it helps.
你要求的是 PHP,但这里是 javascript。只要输入一些“$”就可以了;)。这将返回 WGS84 格式的纬度/经度。不提供任何保证,使用风险自负。
You asked for PHP, but here is javascript. Just throw in some '$' and you should be good ;). This returns Lat/Lon in WGS84. No warranties, use at your own risk.
源链接
source link
为了完整起见,打包在 Composer 中的另一个选项是 https://packagist.org /packages/php-coord/php-coord
它没有很好的记录,但看起来通过东向、北向和区域的组合,您可以返回纬度和经度。例如:
请注意,它似乎不如上面提到的 gPoint 那么准确。
For completeness another option for people that is packaged up in Composer is https://packagist.org/packages/php-coord/php-coord
It's not that well documented but it looks like with a combination of Easting, Northing and Zone you can return the Latitude and Longitude. eg:
Note it doesn't seem as accurate as gPoint mentioned above.
发布的脚本的结果有点符合我的预期,但我在 http 上找到了一个工具://www.uwgb.edu/dutchs/usefuldata/ConvertUTMNoOZ.HTM 这给了我我期望的结果。
我在这里制作了它的 PHP 版本: https://gist.github.com/datagutten/8083549
The results from the script posted is a little of what i expected, but i found a tool on http://www.uwgb.edu/dutchs/usefuldata/ConvertUTMNoOZ.HTM which give me the results i expect.
I have made a PHP version of it here: https://gist.github.com/datagutten/8083549
另一种可能性是包 proj4php (https://github.com/proj4php/proj4php)。非常强大,它允许在许多不同的坐标系之间进行转换。
Another possibility is the package proj4php (https://github.com/proj4php/proj4php). Very powerful and it allows converting from and to many different coordinate systems.