从JavaScript中的链接获取经度/纬度 [英] Getting longitude/latitude from a link in JavaScript

查看:127
本文介绍了从JavaScript中的链接获取经度/纬度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对编程很新。
我需要从收到数据时获得的链接中提取坐标。
我感兴趣的对象如下所示:

I am fairly new to programming. I need to extract coordinates from a link I get when recieving my data. The object I'm interested in looks like this:

 event: {
"type": "message",
"attachments": [{
    "facebookUrl": "https://www.bing.com/maps/default.aspx?v=2&pc=FACEBK&mid=8100&where1=52.217125%2C+5.959805&FORM=FBKPL1&mkt=en-US"
  }],
}

所以,我对 event.attachments [0] .facebookUrl 感兴趣(这是正确的表示法吗?) 。获取坐标lat的正确方法是什么:52.217125和lon:+5.959805?
问题是lon可以用+或 - 开头。我不知道如何使用例如正则表达式匹配。

So, I'm interested in event.attachments[0].facebookUrl (is this the right notation to access it?). What is the right approach to get the coordinates lat: 52.217125 and lon: +5.959805 from this? Problem is that lon can either start with + or -. I have no idea how to do this using for example regex matching.

推荐答案

您正在寻找一个url解析库。从那里你可以获得查询字符串(一切都超过?),并将其提供给查询字符串库,它将为您提供参数。

You're looking for a url parsing library. From there you can get the querystring (everything past the ?), and feed that into a query string library which will give you the arguments.

我没有链接到它们因为找到好的图书馆是一项重要的技能,而且这些图书馆无处不在。

I am not linking to them because finding good libraries is an important skill, and these are ubiquitous libraries.

这篇关于从JavaScript中的链接获取经度/纬度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆