确定字符串是否是有效的地理位置

编程入门 行业动态 更新时间:2024-10-28 17:17:32
本文介绍了确定字符串是否是有效的地理位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一堆位置"——有些是准确的(哈博罗内,博茨瓦纳),有些是地理编码(40.75,-73.997),有些完全没用(#siliconcape).我需要找到一种方法来遍历列表并确定每个字符串和地理编码的城市和国家/地区,并为无效位置返回空值.

I've got a bunch of "locations" - some are accurate (gaborone, botswana), some are geocodes (40.75,-73.997) and some are completely useless (#siliconcape). I need to find a way to run through the list and determine the City and Country of each string and geocode, and return nulls for the invalid locations.

是否有某种库/服务/api/方法可用于确定给定的字符串是否代表有效的地理位置?还要考虑打字错误、订购错误等?

Is there some sort of library/service/api/method that can be used to determine whether or not a given string represents a valid geographical location? While accounting for typos, ordering errors, etc?

推荐答案

可能最简单的方法是使用类似 Google 地理编码 API.它将接受一个字符串并尝试将其解析到一个位置.您可以获得 XML、JSON、CSV 格式的输出.

Probably the easiest method would be to use something like the Google Geocoding API. It'll take a string and attempt to parse it to a location. You can get output as XML, JSON, CSV.

以下是一些 CSV 输出示例:

Here's some example CSV output:

input : gaborone, botswana
output: 200,4,-24.6541100,25.9087390

input : #siliconcape
output: 602,0,0,0

input : 40.75,-73.997
output: 200,8,"324 W 30th St, New York, NY 10001, USA"

这篇关于确定字符串是否是有效的地理位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-18 09:47:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/936325.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   地理位置

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!