javascript - 使用字符串作为 GPS 坐标

标签 javascript html google-maps-api-3 gps

我正在使用 javascript,我有字符串形式的 GPS 坐标,我试图将它们放入 google.maps.LatLng(59.327383, 18.06747) 格式,但我无法决定怎么做。我有一个变量:

GPSlocation = "(37.700421688980136, -81.84535319999998)"

我需要它进入 google.maps.LatLng(num, num) 格式。我怎样才能把这个字符串放在那里?

谢谢!

最佳答案

您可以使用标准字符串操作来提取值:

var GPSlocation = "(37.700421688980136, -81.84535319999998)";
var LatLng = GPSlocation.replace("(", "").replace(")", "").split(", ")
var Lat = parseFloat(LatLng[0]);
var Lng = parseFloat(LatLng[1]);

google.maps.LatLng(Lat, Lng)

关于javascript - 使用字符串作为 GPS 坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12337005/

相关文章:

javascript - 如何在标记中存储更多信息?

javascript - JavaScript 中的 'new' 到底有什么作用?

javascript - 如何将 Base64 编码的 URI 数据转换为文件*服务器端*?

html - 更改 bootstrap 标签的颜色不起作用

javascript - insideHTML 和一个变量

javascript - Google Maps API - 标记工具提示

javascript - Colvis javascript 在数据表和 yadcf 中为工具栏 ui 创建问题

javascript - clearInterval() 在 iPad 上不起作用

javascript - 如何根据输入字段数组验证禁用提交按钮

javascript - Google Maps API V3 - 防止 ImageMapType 换行