python - urls.py 正则表达式帮助坐标

发布于 2024-10-31 10:14:35 字数 458 浏览 4 评论 0原文

我尝试搜索但找不到答案。

我正在尝试编写一个接受坐标(即纬度和经度)的函数。例如,53.345633,-6.267014

然后,这些信息将作为用户当前位置以及前往附近某些地点的方向(我已经将这些位置存储在某处)输入到 Google 地图 API 中,并且有望返回方向。

所以,我几乎已经完成了所有的地图工作,但我无法测试它,因为令人沮丧的是,我根本无法找出 urls.py 内部的正则表达式。

谁能帮我解决这个问题吗?我希望它对你们来说足够简单。我之前尝试过,但惨败!这太令人沮丧了,因为我也快要完成这一部分了!!

感谢您的帮助!

PS 带逗号的坐标格式是否可取?也许 53.345633+-6.267014 会更好(然后我可以使用 my_coords = coords.replace("+", ", ") 或其他东西)?

I tried searching but could not find an answer for this.

I am trying to write a function that takes in coordinates, ie latitude and longitude. For example, 53.345633,-6.267014.

These will then be fed into the Google Maps API as the users current location, and directions to some nearby places (I already have these locations stored somewhere) and the directions will hopefully be returned.

So, I pretty much have all the Maps work done, but I can't test it because, frustratingly enough, I simply cannot figure out the regex for inside urls.py.

Can anyone help me with this? I'm hoping its simple enough for you guys. I tried it earlier but failed miserably! It's so frustrating coz I'm so close to finishing this part too!!

Thanks for the help!

PS Is the format for coordinates advisable, with the comma? Perhaps 53.345633+-6.267014 would be better (then I can just use my_coords = coords.replace("+", ", ") or something)??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眉目亦如画i 2024-11-07 10:14:35

我不确定我明白了,但你可以尝试类似 :

def str2cords(scords):
    return [float(c) for c in scords.split(',')] #or maybe just scords.split(',') since float might mess up the exact cords?

或 regex 的东西:

'/(-?\d+\.\d+),(-?\d+\.\d+)/'

I'm not sure I get it but you can try something like :

def str2cords(scords):
    return [float(c) for c in scords.split(',')] #or maybe just scords.split(',') since float might mess up the exact cords?

or regex :

'/(-?\d+\.\d+),(-?\d+\.\d+)/'
风吹雨成花 2024-11-07 10:14:35

如果您希望点是可选的。

(?P<lon>-?\d+.?\d+)/(?P<lat>-?\d+.?\d+) 

If you want the dot to be optional.

(?P<lon>-?\d+.?\d+)/(?P<lat>-?\d+.?\d+) 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文