Get your conky location aware

2010-02-19-225826_188x44_scrot

Add this in your conkyrc

${exec curl -s "http://api.hostip.info" | xpath -e "//gml:featureMember/Hostip/gml:name/text()" -q} ${exec curl -s "http://api.hostip.info" | xpath -e "//gml:featureMember/Hostip//gml:coordinates/text()" -q}

Hostip is well known as a service provider of the geoclue framework. It translates IP address to geolocation information. The API we use will return a GML document like

<?xml version="1.0" encoding="ISO-8859-1" ?>
<hostipLookupResultSet version="1.0.1" xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.hostip.info/api/hostip-1.0.1.xsd">
 <gml:description>This is the Hostip Lookup Service</gml:description>
 <gml:name>hostip</gml:name>
 <gml:boundedBy>
  <gml:Null>inapplicable</gml:Null>
 </gml:boundedBy>
 <gml:featureMember>
  <hostip>
   <ip>58.212.88.212</ip>
   <gml:name>Nanjing</gml:name>
   <countryName>CHINA</countryName>
   <countryAbbrev>CN</countryAbbrev>
   <!-- Co-ordinates are available as lng,lat -->
   <ipLocation>
    <gml:pointProperty>
     <gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
      <gml:coordinates>118.883,32.05</gml:coordinates>
     </gml:Point>
    </gml:pointProperty>
   </ipLocation>
  </hostip>
 </gml:featureMember>
</hostipLookupResultSet>

Because it uses ip to lookup your address, you cannot expect higher resolution and precision currently.

This entry was written by Sunng , posted on Friday February 19 2010at 11:02 pm , filed under 装备 and tagged , , , . Bookmark the permalink . Post a comment below or leave a trackback: Trackback URL.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word