OpenLayers中toStringHDMS函数用法
时间: 2024-05-05 08:17:44 浏览: 162
OpenLayers中的toStringHDMS函数是将给定的经纬度坐标转换为度分秒格式的字符串。
使用方法如下:
1. 导入OpenLayers库:
```
<script src="https://cdn.bootcdn.net/ajax/libs/openlayers/2.13.1/OpenLayers.js"></script>
```
2. 创建一个经纬度坐标对象:
```
var lonLat = new OpenLayers.LonLat(116.39, 39.9);
```
3. 调用toStringHDMS函数将经纬度坐标转换为度分秒格式的字符串:
```
var hdms = lonLat.toStringHDMS();
```
完整的示例代码如下:
```
<html>
<head>
<script src="https://cdn.bootcdn.net/ajax/libs/openlayers/2.13.1/OpenLayers.js"></script>
<script>
function getHDMS() {
var lonLat = new OpenLayers.LonLat(116.39, 39.9);
var hdms = lonLat.toStringHDMS();
alert(hdms);
}
</script>
</head>
<body>
<button onclick="getHDMS()">获取经纬度坐标的度分秒格式</button>
</body>
</html>
```
阅读全文