27.10.2014 Views

Google Maps API 3

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 10 ■ LOCATION, LOCATION, LOCATION<br />

};<br />

} else {<br />

}<br />

alert('Geo functionality is not available');<br />

function handleError(error) {<br />

alert('Error = ' + error.message);<br />

}<br />

function setPosition(position) {<br />

}<br />

})();<br />

// Creating a LatLng from the position info<br />

var latLng = new google.maps.LatLng(position.coords.latitude,<br />

position.coords.longitude);<br />

// Adding a marker to the map<br />

var marker = new google.maps.Marker({<br />

position: latLng,<br />

map: map<br />

});<br />

// Creating an InfoWindow<br />

var infoWindow = new google.maps.InfoWindow({<br />

content: 'You are here!'<br />

});<br />

// Adding the InfoWindow to the map<br />

infoWindow.open(map, marker);<br />

// Zooming in on the map<br />

map.setZoom(6);<br />

Summary<br />

In this chapter, you learned how to do address lookups using the Geocoder service. This is very useful<br />

for finding the right addresses and the right locations for addresses. You also looked at different ways<br />

of determining the location of the user. This is something increasingly important because we’re<br />

moving toward a context-driven mobile web.<br />

This is also the end of the last chapter of the book. I hope that you’ve enjoyed the book and found it<br />

useful. I also hope that you’re now able to build your own mapping solutions with the <strong>Google</strong> <strong>Maps</strong> <strong>API</strong>.<br />

And remember anything is possible; only your own imagination sets the limit.<br />

242

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!