One of the services available to apps in the mobile world is location, and it is interesting to see all sorts of iPhone apps use it effectively in compelling ways. However, I tend to think that you want browser and desktop apps to have a notion of location as well, and be able to use a somewhat accurate guess, even if it isn’t precise. Location, location, location... right?
To check out whats possible with IP-based location services, I wrote a little Locate Me type of sample that uses the IP address of the client machine using a service such as HostIP.info (you can contribute location and help build their db, if your IP can't be resolved). And then I decided to use this as an excuse to play with the Virtual Earth CTP for Silverlight.
Sitting in my office, when I make a request to http://api.hostip.info/get_html.php?position=true, I get the following response:
Country: UNITED STATES (US)
City: Redmond, WA
Latitude: 47.6742
Longitude: -122.115
While you can also optionally provide an IP address to the service, by default it uses the client’s IP address, which is just what I want. Thankfully, HostIP supports cross-domain access, and that makes things just click. I can have my client code determine latitude and longitude, and place a pushpin on the map.
You can check out the sample code, which is pretty small and self-explanatory (a map control, a GeoLocation service which encapsulates the HostIP service), and you can also check out the live sample, and see how accurate the IP-based lookup is for your own location. Any other services similar to HostIP.info that you've used successfully? I'd love to hear...
Update: - Tim Heuer sent me an updated sample that uses Google's Ajax APIs to determine location, which might have overall better coverage (thanks Tim). Code and live sample updated.
Posted on Thursday, 4/30/2009 @ 9:05 PM
| #
Silverlight