The Yahoo Maps API is powerful, but largely undocumented.
I’m guessing all the docs / marketing materials were written by developers and project managers, with little product management considered — because its damn near impossible to do the simplest things.
My needs weren’t intense , I merely wanted to do this:
– Include a map on a web page that plots an address
One would be amazed at how assbackwards the Yahoo and Google APIs are. Doing something simple like that is a complete PITA. Neither offer the ability to do that “out-of-the-box”.
At the end of this posting is a sample of code that will do this.
Before I get into that, I’ll talk about my learnings from fighting with APIs and a lack of documentation for over 3 hours.
The main issue I had was with the difference between an address and a geopoint. Yahoo will let you instantiate a map from an address, however placing markers must be done with a geopoint. The yahoo library is asynchronous — so when you render the map, it has no idea what the geopoint is… so you’ll need to leverage into their callback chain hooks to later derive the geopoint for the address , or mapcenter. Of course, none of this behavior is documented. Nor are any of the class methods documented in full.
I eventually came up with two possibilities:
– generate a map from an address, in a callback query the center geopoint & label it
– generate a geopoint from an address, in a callback draw the map and label it
I ended up going with the latter. here is the code
Thanks for posting this. What’s so frustrating for me is that even some of the stuff that’s documented doesn’t seem to work properly (yahoo, here).
From:
http://developer.yahoo.com/maps/ajax/V3.8/index.html#YGeoPoint
getCenterLatLon
Returns the lat/lon pair corresponding to the center of the map.
Return value: YGeoPoint object
Running:
var geoPoint = map.getCenterLatLon();
Wouldn’t one expect to get back, oh, say, a YGeoPoint object? I’ve been getting ‘undefined’ for over an hour, with no real recourse to figure this out. I suspect I need to capture an event, like you’re doing here, but that’s not what the (limited) docs indicate. Or am I just reading it wholly wrong?