HTML5: Unterschied zwischen den Versionen

Aus Wikizone
Wechseln zu: Navigation, Suche
(Die Seite wurde neu angelegt: „ == HTML 5 - allgemeines == == HTML 5 Snippets == === Position des Nutzers bestimmen mit HTML5 und Google Gears als Fallback === <pre> // Note that using Google …“)
 
Zeile 4: Zeile 4:
 
== HTML 5 Snippets ==
 
== HTML 5 Snippets ==
 
=== Position des Nutzers bestimmen mit HTML5 und Google Gears als Fallback ===
 
=== Position des Nutzers bestimmen mit HTML5 und Google Gears als Fallback ===
 +
siehe auch [[Google Maps]]
 
<pre>
 
<pre>
 
// Note that using Google Gears requires loading the Javascript
 
// Note that using Google Gears requires loading the Javascript

Version vom 23. November 2011, 17:17 Uhr

HTML 5 - allgemeines

HTML 5 Snippets

Position des Nutzers bestimmen mit HTML5 und Google Gears als Fallback

siehe auch Google Maps

// Note that using Google Gears requires loading the Javascript
// at http://code.google.com/apis/gears/gears_init.js

var initialLocation;
var siberia = new google.maps.LatLng(60, 105);
var newyork = new google.maps.LatLng(40.69847032728747, -73.9514422416687);
var browserSupportFlag =  new Boolean();

function initialize() {
  var myOptions = {
    zoom: 6,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  
  // Try W3C Geolocation (Preferred)
  if(navigator.geolocation) {
    browserSupportFlag = true;
    navigator.geolocation.getCurrentPosition(function(position) {
      initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
      map.setCenter(initialLocation);
    }, function() {
      handleNoGeolocation(browserSupportFlag);
    });
  // Try Google Gears Geolocation
  } else if (google.gears) {
    browserSupportFlag = true;
    var geo = google.gears.factory.create('beta.geolocation');
    geo.getCurrentPosition(function(position) {
      initialLocation = new google.maps.LatLng(position.latitude,position.longitude);
      map.setCenter(initialLocation);
    }, function() {
      handleNoGeoLocation(browserSupportFlag);
    });
  // Browser doesn't support Geolocation
  } else {
    browserSupportFlag = false;
    handleNoGeolocation(browserSupportFlag);
  }
  
  function handleNoGeolocation(errorFlag) {
    if (errorFlag == true) {
      alert("Geolocation service failed.");
      initialLocation = newyork;
    } else {
      alert("Your browser doesn't support geolocation. We've placed you in Siberia.");
      initialLocation = siberia;
    }
    map.setCenter(initialLocation);
  }
}