摆脱城市名称邮编code最简单的方法 [英] Easiest way to get Zip Code from City Name
问题描述
我想勾搭我的一个任务,并通过城市名称,而不是拉链code搜索天气(我怎么有它设置了)。什么是用一个城市名称的输入字符串,并得到一个zip code出来的最简单的方法?帮助是非常AP preciated!谢谢!
I wanted to mess around with an assignment of mine and search for weather by city name rather than by zip code(how i have it set up now). What would be the easiest way to use a city name input string and get a zip code out of it? Help is much appreciated! Thanks!
推荐答案
谷歌可以帮助你来了!
<一个href=\"https://developers.google.com/maps/documentation/geocoding/\">https://developers.google.com/maps/documentation/geocoding/
拉链实际上是由谷歌所谓的postal_ code。
The zip is actually called "postal_code" by Google.
"long_name": "94043",
"short_name": "94043",
"types": postal_code
例如,假设您想要得到克拉克斯顿,MI ...
For example, let's say you want to get the zip for Clarkston, MI...
<一个href=\"http://maps.googleapis.com/maps/api/geo$c$c/json?address=Clarkston+MI&sensor=true\">http://maps.googleapis.com/maps/api/geo$c$c/json?address=Clarkston+MI&sensor=true
这将返回:
{
"results" : [
{
"address_components" : [
{
"long_name" : "Clarkston",
"short_name" : "Clarkston",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Oakland",
"short_name" : "Oakland",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Michigan",
"short_name" : "MI",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "48346",
"short_name" : "48346",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "Clarkston, MI 48346, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 42.7418310,
"lng" : -83.41402409999999
},
"southwest" : {
"lat" : 42.7252370,
"lng" : -83.42880730000002
}
},
"location" : {
"lat" : 42.73511960,
"lng" : -83.41929410
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 42.74331460,
"lng" : -83.40328670
},
"southwest" : {
"lat" : 42.72692350,
"lng" : -83.43530149999999
}
}
},
"types" : [ "locality", "political" ]
}
],
"status" : "OK"
}
修改
如果你没有收到邮政code与第一个电话,你就必须要使用的坐标从第一次调用相同的Web服务的第二个电话。还是很简单的 - 呼吁史蒂文斯点,威斯康星情况如下:
EDIT
If you're not receiving a postal code with that first call, you'll have to make a second call to the same web service using the coordinates from the first call. Still very simple - the call for Stevens Point, WI would be as follows:
<一个href=\"http://maps.googleapis.com/maps/api/geo$c$c/json?latlng=44.52357920000001,-89.5745630&sensor=true\">http://maps.googleapis.com/maps/api/geo$c$c/json?latlng=44.52357920000001,-89.5745630&sensor=true
您可以从位置抢纬度/经度值。希望这有助于!
You can grab the lat/lng values from "location". Hope this helps!
这篇关于摆脱城市名称邮编code最简单的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!