确定字符串是否是有效的地理位置 [英] Determine if a string is a valid geographic location

查看:33
本文介绍了确定字符串是否是有效的地理位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆位置"——有些是准确的(哈博罗内,博茨瓦纳),有些是地理编码(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屋!

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