Sunday, November 6. 2005More fun with the Yahoo! Maps API
Have a look at the source. There is a source link at the top-right on the page. It is about 90 lines of HTML and Javascript and virtually no server-side scripting.
Both input fields are free-form. You can put a city name, a zip code or a full address in the Location field and in the What field you put what you are looking for. There is a special hack that checks for something like 4* and the filters the results to only show you those entries that were rated 4* or higher on Yahoo! Local. You can of course also just put something like "pizza" or "mexican" in that field. Most of the magic here is done by 2 things. The LocalSearchOverlay and the event handling. Note how Map.EVENT_MOVE and Map.EVENT_ZOOM_END are registered events in the onInitialize() function. When you scroll the map or zoom it the onOverlayInit function will get called and the LocalSearchOverlay will be recalculated for the new map coordinates. Same thing happens when you change something in the input fields. The updateMap() function is called which will center the map at the new location and update the LocalSearchOverlay appropriately. There are a few more Javascript tricks here and there in it, like updating the link at the top so you always have a way to grab a link to your current search and send it to someone, but other than that there really isn't all that much to figure out here. Once you understand which events happen when and which methods are available where, you can do some really powerful things with this. It is all documented here: In my last entry I showed how to parse a geocoded XML file and put markers for each entry on the map. Someone asked me how I would do the using the JS-DHTML API instead of the JS-Flash API. It's a whole lot harder in DHTML, but it works. You can see it here: Thursday, November 3. 2005GeoCool!Web 2.0 and the programmable web that I and others have been talking about for a while has mostly been vapourware so far. There are a few generic components that are useful, but it is somewhat limited what you can do with them. And yes, you may consider this a somewhat biased view, but I think Yahoo!'s new geocoding platform is a huge step in the right direction. There is of course the fancy new maps.yahoo.com/beta site which is fun, but as far as I am concerned the killer app here is the geocoding platform that drives this. And it is completely accessible for anyone to use. It's also a sane API that anybody can figure out in minutes. Here are a few tips for using this API from PHP 5. Step 0 - The raw geocoding API
The above code is the contents of geo.inc which you will see included in the following examples.
Easy enough? No real tricks here. We simply send a regular GET request to http://api.local.yahoo.com/MapsService/V1/geocode with the location parameter set to an address. You can try it yourself directly from your browser by clicking here:
You can read more about the geocoding service here: Step 1 - Writing your first application
You can see this one in action here:
http://lerdorf.com/php/ymap/geo1.php Note how it is able to fill in missing details for a partial address. eg.
[precision] => address
[Latitude] => 37.416384
[Longitude] => -122.024853
[Address] => 701 FIRST AVE
[City] => SUNNYVALE
[State] => CA
[Zip] => 94089-1019
[Country] => US
This means that you can use it for a bunch of different things. Address to lat/long, of course, but also address to city, or city to zip code conversions. Or 5-digit zip to 5+4. This is of course rather US-centric right now, but that will improve over time.
Step 2 - Adding a map
We are using the Flash-Javascript API here. Try it out!
http://lerdorf.com/php/ymap/geo2.php?location=701+First+Avenue%2C+94089 And yes, of course the map is draggable. The PanTool() part of the above script adds the panning feature.
This is an API that lets you embed a Flash-based map, but control it with Javascript. It's quite cool even if you think Flash sucks. It is described at:
Step 3 - Making the map prettier
There is a lot of stuff there, but all I really changed was a bit of code related to picking information out of the address so I can fill in the expanded marker, and then the marker code. The last 2 lines of the Javascript there that creates a new CustomPOIMarker and then uses addMarkerByLatLon to the map does the trick. When you mouse over it, it will expand to show the title ($mtitle) and when you click on it, it will show the contents of $info.
Step 4 - But but, why Flash?
navWidget = new NavigatorWidget(); mymap.addWidget(navWidget);That's all. Have a look at it now: http://lerdorf.com/php/ymap/geo4.php?location=701+First+Avenue%2C+94089
But if the thought of Flash still makes your skin crawl. No worries. You can get pretty close to the Flash version
with straight DHTML. Here is the geo4 demo using the DHTML-AJAX API: Step 5 - Something real and useful
You can also let the API figure out your markers for you which makes this even simpler. If the RSS feed is using georss correctly you can use the GeoRSSOverlay mechanism. Here it is using the earthquake RSS feed directly:
There are an amazing number of things you can do with this API. What I have described here is just the surface of it. Overlays and
events can do nifty things. You can even get at the low-level tile api directly using this: Last modified on 2005-11-09 18:24
Thursday, September 1. 2005Flickr API Fun
Flickr's REST API is not broken. You can read all about it at http://flickr.com/services/api. There are links there to various wrappers for the API, but I ended up writing my own. I have a bad habit of doing that. This entry will focus on my PHP wrapper for the Flickr API. It is based on Cal's version and is compatible with it, but it expands on it and puts some PHP 5.1 features to good use. You can see it here: http://lerdorf.com/php/flickr_api.phps Before you get started, in case you want to follow along, go get yourself an API
key at Many functions in the API do not require authentication. Getting a list of someone's public photos, for example, is something anybody can do by just browsing Flickr, or by just going to this URL: http://flickr.com/services/rest/?method=flickr.people.getPublicPhotos&user_id=56053642@N00&api_key=3aba8184848f9263b80795c95529bcd1 Guess what, you just sent a REST Web Services query. Or, slightly cooler. A list of tags related to the tag you provide based on Flickr's clustering code. http://flickr.com/services/rest/?method=flickr.tags.getRelated&tag=monkey&api_key=3aba8184848f9263b80795c95529bcd1 Last modified on 2006-04-24 20:28
|
Why a toys page?I love geeky toys and people are always asking me about them. So this page is where I keep track of the gadgets that interest me.
QuicksearchSyndicate This BlogMy LinksPopular EntriesTemplate dropdownBlog AdministrationCreative Commons |
