从纬度和经度获取城市,州,国家

时间:2011-02-06 07:03:25

标签: javascript

如何使用javascript从纬度和经度获取城市,州,国家/地区。

3 个答案:

答案 0 :(得分:2)

查看Google Geocoding API,看看是否符合您的需求。

答案 1 :(得分:2)

如果Google地理编码API不可能,那么Yahoo PlaceFinder Web Service

怎么样?

例如,此查询 http://where.yahooapis.com/geocode?location=701+First+Ave,+Sunnyvale,+CA&appid=yourappid

将返回此XML结果

<?xml version="1.0" encoding="UTF-8"?>  
<ResultSet version="1.0">  
  <Error>0</Error>  
  <ErrorMessage>No error</ErrorMessage>  
  <Locale>us_US</Locale>  
  <Quality>87</Quality>  
  <Found>1</Found>  
  <Result>  
    <quality>87</quality>  
    <latitude>37.416275</latitude>  
    <longitude>-122.025092</longitude>  
    <offsetlat>37.416397</offsetlat>  
    <offsetlon>-122.025055</offsetlon>  
    <radius>500</radius>  
    <name></name>  
    <line1>701 1st Ave</line1>  
    <line2>Sunnyvale, CA  94089-1019</line2>  
    <line3></line3>  
    <line4>United States</line4>  
    <house>701</house>  
    <street>1st Ave</street>  
    <xstreet></xstreet>  
    <unittype></unittype>  
    <unit></unit>  
    <postal>94089-1019</postal>  
    <neighborhood></neighborhood>  
    <city>Sunnyvale</city>  
    <county>Santa Clara County</county>  
    <state>California</state>  
    <country>United States</country>  
    <countrycode>US</countrycode>  
    <statecode>CA</statecode>  
    <countycode></countycode>  
    <uzip>94089</uzip>  
    <hash>DDAD1896CC0CDC41</hash>  
    <woeid>12797150</woeid>  
    <woetype>11</woetype>  
  </Result>  
</ResultSet>

您可以使用XML,JSON,序列化PHP等来请求结果。

答案 2 :(得分:2)

<form id="form1" runat="server">
<div>
    <script type="text/javascript" src="http://j.maxmind.com/app/geoip.js" ></script>
    <br />Country Code:
    <script type="text/javascript">document.write(geoip_country_code());</script>
    <br />Country Name:
    <script type="text/javascript">document.write(geoip_country_name());</script>
    <br />City:
    <script type="text/javascript">document.write(geoip_city());</script>
    <br />Region:
    <script type="text/javascript">document.write(geoip_region());</script>
    <br />Region Name:
    <script type="text/javascript">document.write(geoip_region_name());</script>
    <br />Latitude:
    <script type="text/javascript">document.write(geoip_latitude());</script>
    <br />Longitude:
    <script type="text/javascript">document.write(geoip_longitude());</script>
    <br />Postal Code:
    <script type="text/javascript">document.write(geoip_postal_code());</script>

</div>
</form>