Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


	<meta charset="UTF-8">
	<title>Ejemplo Geolocalización</title>
	<script type="text/javascript" src=""></script>
	<script type="text/javascript" src=""></script>
	<link rel="stylesheet" type="text/css" href="css/estilo.css">

	<article id="mapa">
 	<input type="button" id="parar" value="Parar" onclick="detener();"/>


                body {
   background: #2c2c2c;
article {
    position: relative;
    overflow: hidden;
    padding: 20px;
    background: rgba(0,0,0,0.7);
    margin: 50px auto;
    width: 70%;
    border: 2px solid #FFA800;
    border-radius: 10px;
    box-shadow: 0 0 4px #FFA800;
    color: #FFA800;
    text-align: center;

#mapa {
    height: 400px;
    padding: 0;
    margin-bottom: 20px;

#parar {
    display: block;
    margin: 20px auto 30px;
    width: 100px;
    border: 2px solid #FFA800;
    border-radius: 10px;
    box-shadow: 0 0 4px #FFA800;
    color: #FFA800;

#parar:hover {
    border: 2px solid #2E5E90;
    box-shadow: 0 0 4px #2E5E90;
    color: #2E5E90;


                var watchId;
var mapa = null;
var mapaMarcador = null;	

if (navigator.geolocation) {
	watchId = navigator.geolocation.watchPosition(mostrarPosicion, mostrarErrores, opciones);	
} else {
	alert("Tu navegador no soporta la geolocalización, actualiza tu navegador.");

function mostrarPosicion(posicion) {
	var latitud = posicion.coords.latitude;
	var longitud = posicion.coords.longitude;
	var precision = posicion.coords.accuracy;

	var miPosicion = new google.maps.LatLng(latitud, longitud);

	// Se comprueba si el mapa se ha cargado ya 
	if (mapa == null) {
		// Crea el mapa y lo pone en el elemento del DOM con ID mapa
		var configuracion = {center: miPosicion, zoom: 16, mapTypeId: google.maps.MapTypeId.HYBRID};
		mapa = new google.maps.Map(document.getElementById("mapa"), configuracion);

		// Crea el marcador en la posicion actual
		mapaMarcador = new google.maps.Marker({position: miPosicion, title:"Esta es tu posición"});
	} else {
		// Centra el mapa en la posicion actual
		// Pone el marcador para indicar la posicion

function mostrarErrores(error) {
	switch (error.code) {
 		case error.PERMISSION_DENIED:
  			alert('Permiso denegado por el usuario'); 
    		alert('Posición no disponible');
     	case error.TIMEOUT:
      		alert('Tiempo de espera agotado');
         	alert('Error de Geolocalización desconocido :' + error.code);

var opciones = {
	enableHighAccuracy: true,
	timeout: 10000,
	maximumAge: 1000

function detener() {