Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions miguelGarcia/public/whereIAm/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!doctype html>
<html lang="en">

<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

<title>WhereIAm</title>


</head>
<body>
<div class="container">
<div class="row ">
<p class="text-right display-2 "> where i am? </p>

</div>
<div style="height: 600px" id="map"></div>

</div>
<script src="whereIAm.js"></script>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tu script siempre va al final de las dependencias..

<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB0AeWwQW28gYeltyIMsTRYGh-Zu3YEYLQ&callback=searchMe"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

necesitabamos bootstrap?

async defer></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</body>
</html>
332 changes: 332 additions & 0 deletions miguelGarcia/public/whereIAm/whereIAm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,332 @@





let posicion = {};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No necesitas esta variable global...



//probando la geolocalizacion
function searchMe(){
navigator.geolocation.getCurrentPosition(geo_success, geo_error);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

geo_error no hace más que ejecutar... altSearch, pásalo directamente ;-)

}



function geo_success(position) {
posicion.latitud = parseFloat(position.coords.latitude.toFixed(4));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Podrías meter esta transformación parseFloat(position.coords.latitude.toFixed(4)); en una función.. para reutilizarla después

posicion.longitud = parseFloat(position.coords.longitude.toFixed(4));
initMap(posicion.latitud,posicion.longitud);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No te hace falta poSicion si ya tienes posiTion

}

function geo_error() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esto parece un poco poltergeist

altSearch();
}

async function altSearch(){

const jsonIp = await fetch("https://jsonip.com")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Podrías hacerlo así... piensa que la idea de usar await es para evitar tanto then, sería interesante no dejarte la gestión de errores en el tintero con try/catch

    const jsonIp = await fetch("https://jsonip.com");
    const IP = await jsonIp.json()
    const ipRequest = await fetch(`http://ip-api.com/json/${IP}?fields=lat,lon`)
    const posObj = ipRequest.json()
    initMap(posObj.lat,posObj.lon);

Aunque viendo la documentación de ip-api.com, podrías reducir esto a un único paso llamando a http://ip-api.com/json/ sin queries.

.then((response) => {
return response.json()
})

const clientIp = jsonIp.ip

let posObj = await fetch(`http://ip-api.com/json/${clientIp}?fields=lat,lon`)
.then((response) => {
return response.json()
})

initMap(posObj.lat,posObj.lon);
}




let map = document.getElementById('map');
let marker;

function initMap(long,lat) {
map = new google.maps.Map(map, {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mala idea reutilziar una variable map que era un selector para que luego sea otro objeto. 😢

center: {lat: long, lng: lat},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cómo es que lat es long ???

Nota: con es6 puedes dejarlo en center: {lat, lng},

zoom: 14,
styles:[
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Este array podría estar expuesto en otro fichero como style_maps.js o similar...

{
"featureType": "all",
"elementType": "labels",
"stylers": [
{
"visibility": "on"
}
]
},
{
"featureType": "all",
"elementType": "labels.text.fill",
"stylers": [
{
"saturation": 36
},
{
"color": "#000000"
},
{
"lightness": 40
}
]
},
{
"featureType": "all",
"elementType": "labels.text.stroke",
"stylers": [
{
"visibility": "on"
},
{
"color": "#000000"
},
{
"lightness": 16
}
]
},
{
"featureType": "all",
"elementType": "labels.icon",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "administrative",
"elementType": "geometry.fill",
"stylers": [
{
"color": "#000000"
},
{
"lightness": 20
}
]
},
{
"featureType": "administrative",
"elementType": "geometry.stroke",
"stylers": [
{
"color": "#000000"
},
{
"lightness": 17
},
{
"weight": 1.2
}
]
},
{
"featureType": "administrative.locality",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#c4c4c4"
}
]
},
{
"featureType": "administrative.neighborhood",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#707070"
}
]
},
{
"featureType": "landscape",
"elementType": "geometry",
"stylers": [
{
"color": "#000000"
},
{
"lightness": 20
}
]
},
{
"featureType": "poi",
"elementType": "geometry",
"stylers": [
{
"color": "#000000"
},
{
"lightness": 21
},
{
"visibility": "on"
}
]
},
{
"featureType": "poi.business",
"elementType": "geometry",
"stylers": [
{
"visibility": "on"
}
]
},
{
"featureType": "road.highway",
"elementType": "geometry.fill",
"stylers": [
{
"color": "#be2026"
},
{
"lightness": "0"
},
{
"visibility": "on"
}
]
},
{
"featureType": "road.highway",
"elementType": "geometry.stroke",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "road.highway",
"elementType": "labels.text.fill",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "road.highway",
"elementType": "labels.text.stroke",
"stylers": [
{
"visibility": "off"
},
{
"hue": "#ff000a"
}
]
},
{
"featureType": "road.arterial",
"elementType": "geometry",
"stylers": [
{
"color": "#000000"
},
{
"lightness": 18
}
]
},
{
"featureType": "road.arterial",
"elementType": "geometry.fill",
"stylers": [
{
"color": "#575757"
}
]
},
{
"featureType": "road.arterial",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#ffffff"
}
]
},
{
"featureType": "road.arterial",
"elementType": "labels.text.stroke",
"stylers": [
{
"color": "#2c2c2c"
}
]
},
{
"featureType": "road.local",
"elementType": "geometry",
"stylers": [
{
"color": "#000000"
},
{
"lightness": 16
}
]
},
{
"featureType": "road.local",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#999999"
}
]
},
{
"featureType": "road.local",
"elementType": "labels.text.stroke",
"stylers": [
{
"saturation": "-52"
}
]
},
{
"featureType": "transit",
"elementType": "geometry",
"stylers": [
{
"color": "#000000"
},
{
"lightness": 19
}
]
},
{
"featureType": "water",
"elementType": "geometry",
"stylers": [
{
"color": "#000000"
},
{
"lightness": 17
}
]
}
]
});

marker = new google.maps.Marker({
position: {lat: long, lng: lat},
label: "I",
map
});

}

apiKey= "AIzaSyB0AeWwQW28gYeltyIMsTRYGh-Zu3YEYLQ";