mirror of
https://github.com/Erreur32/html5demos.git
synced 2024-09-30 05:11:29 +02:00
141 lines
3.0 KiB
HTML
141 lines
3.0 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
|
<meta name="viewport" content="width=620" />
|
|
<title>HTML5 Demo: geolocation</title>
|
|
<style>
|
|
body {
|
|
font: normal 16px/20px Helvetica, sans-serif;
|
|
background: rgb(237, 237, 236);
|
|
margin: 0;
|
|
margin-top: 40px;
|
|
padding: 0;
|
|
}
|
|
|
|
section, header, footer {
|
|
display: block;
|
|
}
|
|
|
|
#wrapper {
|
|
width: 600px;
|
|
margin: 0 auto;
|
|
background: #fff url(images/shade.jpg) repeat-x center bottom;
|
|
-moz-border-radius: 10px;
|
|
-webkit-border-radius: 10px;
|
|
border-top: 1px solid #fff;
|
|
padding-bottom: 76px;
|
|
}
|
|
|
|
h1 {
|
|
padding-top: 10px;
|
|
}
|
|
|
|
h2 {
|
|
font-size: 100%;
|
|
font-style: italic;
|
|
}
|
|
|
|
header,
|
|
article > *,
|
|
footer > * {
|
|
margin: 20px;
|
|
}
|
|
|
|
footer > * {
|
|
margin: 20px;
|
|
color: #999;
|
|
}
|
|
|
|
#status {
|
|
padding: 5px;
|
|
color: #fff;
|
|
background: #ccc;
|
|
}
|
|
|
|
#status.fail {
|
|
background: #c00;
|
|
}
|
|
|
|
#status.success {
|
|
background: #0c0;
|
|
}
|
|
|
|
|
|
</style>
|
|
<script src="h5utils.js"></script>
|
|
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
|
|
</head>
|
|
<body>
|
|
<section id="wrapper">
|
|
<header>
|
|
<h1>Geolocation</h1>
|
|
</header>
|
|
<article>
|
|
<p>Finding your location: <span id="status">checking...</span></p>
|
|
</article>
|
|
<footer><a href="/">HTML5 demo</a></footer>
|
|
</section>
|
|
<script>
|
|
function success(position) {
|
|
var s = document.querySelector('#status');
|
|
|
|
if (s.className == 'success') {
|
|
// not sure why we're hitting this twice in FF, I think it's to do with a cached result coming back
|
|
return;
|
|
}
|
|
|
|
s.innerHTML = "found you!";
|
|
s.className = 'success';
|
|
|
|
var mapcanvas = document.createElement('div');
|
|
mapcanvas.id = 'mapcanvas';
|
|
mapcanvas.style.height = '400px';
|
|
mapcanvas.style.width = '100%';
|
|
|
|
document.querySelector('article').appendChild(mapcanvas);
|
|
|
|
var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
|
|
var myOptions = {
|
|
zoom: 15,
|
|
center: latlng,
|
|
mapTypeControl: false,
|
|
navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
|
|
mapTypeId: google.maps.MapTypeId.ROADMAP
|
|
};
|
|
var map = new google.maps.Map(document.getElementById("mapcanvas"), myOptions);
|
|
|
|
var marker = new google.maps.Marker({
|
|
position: latlng,
|
|
map: map,
|
|
title:"You are here!"
|
|
});
|
|
}
|
|
|
|
function error(msg) {
|
|
var s = document.querySelector('#status');
|
|
s.innerHTML = typeof msg == 'string' ? msg : "failed";
|
|
s.className = 'fail';
|
|
|
|
// console.log(arguments);
|
|
}
|
|
|
|
if (navigator.geolocation) {
|
|
navigator.geolocation.getCurrentPosition(success, error);
|
|
} else {
|
|
error('not supported');
|
|
}
|
|
|
|
|
|
</script>
|
|
<script>
|
|
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
|
|
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
|
|
</script>
|
|
<script>
|
|
try {
|
|
var pageTracker = _gat._getTracker("UA-1656750-18");
|
|
pageTracker._trackPageview();
|
|
} catch(err) {}</script>
|
|
</body>
|
|
</html> |