HTML and CSS Reference
In-Depth Information
Finally, we check the value of the units drop-down to find out if the user wanted the
total distance in miles or kilometers. Then we call one of our helper functions meter
sToKilometers() or metersToMiles() to convert meters into kilometers or miles,
respectively, and output the value to the distance div element.
See Also
For more about getting directions from the Google Maps API, see http://code.google
.com/apis/maps/documentation/javascript/services.html#Directions .
8.6 Example: Starbucks to Starbucks
Problem
You want to get directions from the nearest Starbucks to the next closest Starbucks.
Solution
Use SimpleGeo's Places API to find the closest Starbucks to the user's current location
and then, once that location is set, make a second API call to SimpleGeo to find the
next closest Starbucks location. Then use the Google Maps API to give directions from
the first Starbucks to the second Starbucks.
To begin, add the SimpleGeo API to the collection of JavaScript libraries:
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script src="http://j.maxmind.com/app/geoip.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.js">
</script>
<script src="http://cdn.simplegeo.com/js/1.2/simplegeo.places.jq.min.js">
</script>
SimpleGeo is free, but it does require you to sign up to get an API key (see http://
simplegeo.com ). Once you've signed up, you can find the API key by clicking the Tokens
menu and then the JSONP Tokens submenu, as shown in Figure 8-5 .
 
Search WWH ::




Custom Search