Game Development Reference
In-Depth Information
var options = {
zoom: 16,
center: coords,
mapTypeControl: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
// Create a map, and inject it into the DOM
element referenced
var map = new google.maps.Map(container,
options);
// Create a marker and associate it with our
map
var marker = new google.maps.Marker({
position: coords,
map: map,
title: "Where's me?"
});
}
While the preceding example might not be the most exciting piece of software you've
seen, it does a great job illustrating two powerful points. First, the geolocation API is
powerful, yet, it is also possibly the easiest of all other HTML5 APIs in terms of all
the functionality it offers and everything you need to know in order to use it. Second,
the preceding snippet shows how open the web platform is and how much we can
potentially accomplish simply by taking advantage of other people's work.
Running the preceding code will result in a very nice looking map covering the en-
tirety of the screen, with the central point of the map being the user's current location,
as shown in the following screenshot. Keep in mind that Google Maps is just one
example of the many free APIs that we can use in conjunction with such powerful
HTML5 features as geolocation.
Search WWH ::




Custom Search