Reputation: 38352
how can i Get City, State, Country from Latitude and Longitude using javascript.
Upvotes: 2
Views: 6970
Reputation: 137
<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>
Upvotes: 2
Reputation: 1346
If the Google Geocoding API is out of the question then how about the Yahoo PlaceFinder Web Service?
For example, this query
http://where.yahooapis.com/geocode?location=701+First+Ave,+Sunnyvale,+CA&appid=yourappid
Will return this XML result
<?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>
You can request the result(s) in XML, JSON, serialized PHP, etc.
Upvotes: 2
Reputation: 6295
Take a look at the Google Geocoding API and see if that doesn't suit your needs.
Upvotes: 2