-
Notifications
You must be signed in to change notification settings - Fork 11
añadir geolocalizacion por google #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: miguel-nasaRoverChallenge
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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> | ||
| <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB0AeWwQW28gYeltyIMsTRYGh-Zu3YEYLQ&callback=searchMe" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,332 @@ | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| let posicion = {}; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
|
|
||
|
|
||
| function geo_success(position) { | ||
| posicion.latitud = parseFloat(position.coords.latitude.toFixed(4)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Podrías meter esta transformación |
||
| posicion.longitud = parseFloat(position.coords.longitude.toFixed(4)); | ||
| initMap(posicion.latitud,posicion.longitud); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No te hace falta |
||
| } | ||
|
|
||
| function geo_error() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Esto parece un poco |
||
| altSearch(); | ||
| } | ||
|
|
||
| async function altSearch(){ | ||
|
|
||
| const jsonIp = await fetch("https://jsonip.com") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Podrías hacerlo así... piensa que la idea de usar 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 |
||
| .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, { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mala idea reutilziar una variable |
||
| center: {lat: long, lng: lat}, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cómo es que Nota: con es6 puedes dejarlo en |
||
| zoom: 14, | ||
| styles:[ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Este array podría estar expuesto en otro fichero como |
||
| { | ||
| "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"; | ||
There was a problem hiding this comment.
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..