Mar 5
PHP PHP 5, JSON from pecl cvs, Map Tile API and the Yui Connection Manager. Toss them in a bag and shake and you get something like this. Enter a city name, or even a pseudo-name like Philly or SFO and hit return. Each time you enter a new name you will get a map tile for that city.

It's not all that fancy, but it sure is easy to do:



33 lines total which includes about 6 lines of PHP which consists mostly of building the URL to the map tile service. Then the Javascript which has a callback function to read the form values and make the backend GET request and a simple function to take the JSON response and add the map tile to the document. And finally the actual HTML form.

With a slight tweak you can change it to make a nice geocode lookup field.




So, fire up your text editors and start writing some plugins for blog and forum packages and perhaps image gallery applications as well.

Posted by Rasmus


Last modified on 2006-03-09 01:31

View as PDF: This entry | This month | Full blog

0 Trackbacks

  1. No Trackbacks

7 Comments

Display comments as(Linear | Threaded)
  1. Adam Trachtenberg says:

    Cool! But why the PHP deserialization and JSON reserialization?

    Am I missing something or can you switch to format=json and switch to a straight echo file_get_contents($src); instead?

  2. Rasmus says:

    Because there is no output=json for the maps API ;(

  3. Adam Trachtenberg says:

    I didn't check the docs, but this seems to work for me:

    http://api.local.yahoo.com/MapsService/V1/mapImage?appid=rlerdorf&location=SFO&output=json&image_width=300&image_height=300&zoom=7

  4. Rasmus says:

    True, but if you check:

    http://developer.yahoo.net/maps/rest/V1/mapImage.html

    and

    http://developer.yahoo.net/maps/rest/V1/geocode.html

    You will see that this is not documented, so relying on it at this point would be a bad idea. But yes, you are right, you could pass the json straight through, of course.

  5. Adam Trachtenberg says:

    Hum... I'll let McManus know his docs are out of date. :)

  6. Nico Edtinger says:

    When I try it with "Vienna" I get a flood of JavaScript errors. The output of the post to /php/ymap/yajax.php is:

    Warning: file_get_contents(http://api.local.yahoo.com/MapsService/V1/mapImage?appid=rlerdorf&location=vienna&output=php&image_width=300&image_height=300&zoom=7) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
    in /var/www/lerdorf.com/php/ymap/yajax.php on line 7
    false

    and then it tries to post again and again and ...

  7. Rasmus says:

    Yeah, I skipped error checking to keep the example short.

Add Comment


E-Mail addresses will not be displayed and will only be used for E-Mail notifications.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.