Petar Strinic

and all those sorts of things…

While playing around with a weather widget, the other day, I though to myself why not use HTML5’s geolocation capabilities to show the user the weather for their current location automatically. This turns out to be exceedingly easy, if you’re willing to live with a couple of small assumptions, such as it’s safe to use a regular expression to parse the zip code out of Google Maps API’s formatted_address. Although they do offer a more specific “postal code” field as part of the address object, this is just a little quicker to get to, if you’re willing to assume a format like “, IL 60601”.

In easy steps…

1. Get the user’s latitude and longitude, we can do something like this:

2. Get the address information from Google maps and do the regex hack to get the zip out of the formatted_address.

Shady demo: http://petarstrinic.com/examples/whatIsMyZip.html

Share

April 7th, 2012

Posted In: Misc

Tags: , , ,

8 Comments