确认用户输入的位置字符串是有效的地理位置? [英] Verify user input location string is a valid geographic location?

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

问题描述

我接受应该是地理位置的用户输入.我想验证用户输入的内容是否描述了位置-例如,邮政编码,机场代码,街道地址,城市名称等.

I'm accepting a user input which is supposed to be a geographic location. I would like to validate that what the user has entered describes a location--e.g., postal code, airport code, street address, city name, etc.

显而易见的答案是使用 Google Geocode API 来完成请求用户输入,看看是否得到任何结果.)但是地理编码ToS禁止这样做:

The obvious answer is to use the Google Geocode API to do a request for the user's input and see if I get any results.) However the geocode ToS forbids this:

...地理编码API只能与Google地图结合使用;禁止对结果进行地理编码而不在地图上显示.

...the Geocoding API may only be used in conjunction with a Google map; geocoding results without displaying them on a map is prohibited.

有人知道替代品吗?

推荐答案

雅虎还具有地理位置API ,它具有较少的TOS限制.通过查询位置,如果您收到非null结果集,那么您知道它的有效位置.

Yahoo also has a geolocation API which has a less-restrictive TOS. By querying for a location, if you receive a non-null result set then you know its a valid place.

# A query for New York...
http://query.yahooapis.com/v1/public/yql?q=select%20%2a%20from%20geo.places%20where%20text='New+York'&format=json
# Results in a response
{"query":{"count":10,"created":"2013-01-11T18:40:32Z","lang":"en-US","results":{"place":[... places ... ] }}}

# A query for junk
http://query.yahooapis.com/v1/public/yql?q=select%20%2a%20from%20geo.places%20where%20text='kqpo234xk'&format=json
# Results in null
{"query":{"count":0,"created":"2013-01-11T18:39:21Z","lang":"en-US","results":null}}

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

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