views:

678

answers:

3

I have a list of addresses from a Database for which I'd like to put markers on a Yahoo Map. The addMarker() method on YMap takes a YGeoPoint, which requires a latitude and longitude. However, Yahoo Maps must know how to convert from addresses because drawZoomAndCenter(LocationType,ZoomLevel) can take an address. I could convert by using drawZoomAndCenter() then getCenterLatLon() but is there a better way, which doesn't require a draw?

A: 

If you're working with U.S. addresses, you can use geocoder.us, which has APIs.

Also, Google Maps Hacks has a hack, "Hack 62. Find the Latitude and Longitude of a Street Address", for that.

Paul Reiners
This is only readable if you have a Safari account - so no use to me.
Nick Fortescue
+1  A: 

You can ask the map object to do the geoCoding, and catch the callback:

<script type="text/javascript"> 
var map = new YMap(document.getElementById('map'));
map.drawZoomAndCenter("Algeria", 17);

map.geoCodeAddress("Cambridge, UK");

YEvent.Capture(map, EventsList.onEndGeoCode, function(geoCode) {
    if (geoCode.success)
     map.addOverlay(new YMarker(geoCode.GeoPoint));
});
</script>

One thing to beware of -- in this example the drawAndZoom call will itself make a geoCoding request, so you'll get the callback from that too. You might want to filter that out, or set the map's centre based on a GeoPoint.

David Bick
A: 

Sorry for being total code illiterate,

How do I add multiple locations, such as

-202 first street, 92101

-miramar way, san diego, ca

-5850 university avenue, san diego, ca

-92116

into one screen? and have them all mapped out.

thank you.