añadir geolocalizacion por google#61
añadir geolocalizacion por google#61gargonmi wants to merge 1 commit intomiguel-nasaRoverChallengefrom
Conversation
|
|
||
|
|
||
|
|
||
| let posicion = {}; |
There was a problem hiding this comment.
No necesitas esta variable global...
|
|
||
|
|
||
| function geo_success(position) { | ||
| posicion.latitud = parseFloat(position.coords.latitude.toFixed(4)); |
There was a problem hiding this comment.
Podrías meter esta transformación parseFloat(position.coords.latitude.toFixed(4)); en una función.. para reutilizarla después
| function geo_success(position) { | ||
| posicion.latitud = parseFloat(position.coords.latitude.toFixed(4)); | ||
| posicion.longitud = parseFloat(position.coords.longitude.toFixed(4)); | ||
| initMap(posicion.latitud,posicion.longitud); |
There was a problem hiding this comment.
No te hace falta poSicion si ya tienes posiTion
| initMap(posicion.latitud,posicion.longitud); | ||
| } | ||
|
|
||
| function geo_error() { |
There was a problem hiding this comment.
Esto parece un poco poltergeist
|
|
||
| //probando la geolocalizacion | ||
| function searchMe(){ | ||
| navigator.geolocation.getCurrentPosition(geo_success, geo_error); |
There was a problem hiding this comment.
geo_error no hace más que ejecutar... altSearch, pásalo directamente ;-)
| let marker; | ||
|
|
||
| function initMap(long,lat) { | ||
| map = new google.maps.Map(map, { |
There was a problem hiding this comment.
mala idea reutilziar una variable map que era un selector para que luego sea otro objeto. 😢
|
|
||
| function initMap(long,lat) { | ||
| map = new google.maps.Map(map, { | ||
| center: {lat: long, lng: lat}, |
There was a problem hiding this comment.
Cómo es que lat es long ???
Nota: con es6 puedes dejarlo en center: {lat, lng},
| map = new google.maps.Map(map, { | ||
| center: {lat: long, lng: lat}, | ||
| zoom: 14, | ||
| styles:[ |
There was a problem hiding this comment.
Este array podría estar expuesto en otro fichero como style_maps.js o similar...
| <div style="height: 600px" id="map"></div> | ||
|
|
||
| </div> | ||
| <script src="whereIAm.js"></script> |
There was a problem hiding this comment.
Tu script siempre va al final de las dependencias..
|
|
||
| </div> | ||
| <script src="whereIAm.js"></script> | ||
| <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB0AeWwQW28gYeltyIMsTRYGh-Zu3YEYLQ&callback=searchMe" |
There was a problem hiding this comment.
necesitabamos bootstrap?
Geolocalizacion con google (quiera o no el usuario)