我正在开发一个约会网站,用户可以在其中注册
世界。约会部分再次划分为城市,遍布各地
世界。
我在这里看到的问题是,我没有涵盖所有城市的数据库
全球各地。
我正在用手确认每个用户,这样我就有机会进行审核
用户所在城市和国家
主要的主要方法是,在数据库中为每个城市提供“city_id”。
就像一个人从纽约加入,我给它id US_NEWYORK
如果此人从法兰克福加入,则会获得ID DE_FRANKFURT
这两个用户在数据库中仍然拥有自己的城市名称,而且它是
写下来就像写下来一样。例如,
“法兰克福”而不是“法兰克福”为正确的名称或,
“NYC”而不是“纽约”的正确名称。
通过这种方式,我可以让每个用户都能写作,并且可以为城市提供特殊的身份证明 并通过该ID运行所有查询。
这是我自己的解决方案,我认为这并不是那么糟糕。你有没有 一个想法我能做得更好吗?
我想请记住,我需要来自每个国家的每个城市
我正在运行这项服务,如果你想推荐我会得到一个数据库
来自某个地方:)
感谢阅读。
答案 0 :(得分:1)
为什么不使用geonames.org或Google的地理编码API等地理编码服务器来查找位置的规范名称,以及纬度/经度。我假设您需要某种规范形式的位置,以便找到最接近的匹配,对吧?那么,纬度/经度是去那里的方式。
例如,如果你向谷歌询问“法兰克福”,就像这样:
curl 'http://maps.googleapis.com/maps/api/geocode/xml?address=Frankfurt%20am%20Main&sensor=false'
你得到了所有这些:
geocode/xml?address=Frankfurt%20am%20Main&sensor=false'
<?xml version="1.0" encoding="UTF-8"?>
<GeocodeResponse>
<status>OK</status>
<result>
<type>locality</type>
<type>political</type>
<formatted_address>Frankfurt, Germany</formatted_address>
<address_component>
<long_name>Frankfurt</long_name>
<short_name>Frankfurt</short_name>
<type>locality</type>
<type>political</type>
</address_component>
<address_component>
<long_name>Frankfurt am Main</long_name>
<short_name>Frankfurt am Main</short_name>
<type>administrative_area_level_2</type>
<type>political</type>
</address_component>
<address_component>
<long_name>Hesse</long_name>
<short_name>HE</short_name>
<type>administrative_area_level_1</type>
<type>political</type>
</address_component>
<address_component>
<long_name>Germany</long_name>
<short_name>DE</short_name>
<type>country</type>
<type>political</type>
</address_component>
<geometry>
<location>
<lat>50.1115118</lat>
<lng>8.6805059</lng>
</location>
<location_type>APPROXIMATE</location_type>
<viewport>
<southwest>
<lat>49.9968858</lat>
<lng>8.4243871</lng>
</southwest>
<northeast>
<lat>50.2258641</lat>
<lng>8.9366247</lng>
</northeast>
</viewport>
<bounds>
<southwest>
<lat>50.0155200</lat>
<lng>8.4727150</lng>
</southwest>
<northeast>
<lat>50.2269512</lat>
<lng>8.8004960</lng>
</northeast>
</bounds>
</geometry>
</result>
</GeocodeResponse>
答案 1 :(得分:1)
看起来相当全面。