HTML and CSS Reference
In-Depth Information
directionsRenderer = new google.maps.DirectionsRenderer();
directionsRenderer.setMap(map);
// wire up button click
$('#go').click(function () {
// Use our new getLatLng with fallback and define an inline function
// to handle the callback.
getLatLng(function (latitude, longitude, isMaxMind) {
// use SimpleGeo to get closest Starbucks
var query = "Starbucks";
geoclient.search(latitude, longitude, { q: query, radius: 20,
num: 1 }, function (err, dataStart) {
if (err) {
error(err);
} else {
// We only asked for one result and SimpleGeo returns results
// based on distance so the closest is first, so make sure we
// got a result.
if (dataStart.features.length == 1) {
// save start coordinates and address
var startLat =
dataStart.features[0].geometry.coordinates[1];
var startLng =
dataStart.features[0].geometry.coordinates[0];
var startAddress =
dataStart.features[0].properties['address'];
// save in Google LatLng as well
var start = new google.maps.LatLng(startLat, startLng);
// look up the closest Starbucks to the one we just found
geoclient.search(startLat, startLng, { q: query, radius:
20, num: 2 }, function (err, dataEnd) {
if (err) {
error(err);
} else {
// This time we asked for two results; the first
// result should be the starting Starbucks,
// so this time access the second result.
if (dataEnd.features.length == 2) {
// save end coordinates and address
var endLat =
dataEnd.features[1].geometry.coordinates[1];
var endLng =
dataEnd.features[1].geometry.coordinates[0];
var endAddress =
dataEnd.features[1].properties['address'];
// save in Google LatLng as well
var end = new google.maps.LatLng(endLat,
endLng);
// Now add directions from starting Starbucks
// to ending one.
// Set the request options:
var request = {
origin: start,
 
Search WWH ::




Custom Search