确定一个字符串是一个有效的地理位置 [英] Determine if a string is a valid geographic location
问题描述
我有一大堆的位置 - 有些是准确的(博茨瓦纳哈博罗内),有些是地缘codeS(40.75,-73.997),有些是完全无用的(#siliconcape)。我需要找到每个字符串和地缘code的方式,通过列表来运行,并确定城市和乡村,并为无效的位置返回空值。
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.
是否有某种可用于确定给定串重新$ P $是否psents有效地理位置库/服务/ 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?
推荐答案
也许最简单的方法是使用类似的谷歌地理编码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屋!