Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. const express = require('express')
  2. const app = express();
  3.  
  4. let port = process.env.PORT || 3030;
  5.  
  6. app.set('view engine', 'jade');
  7.  
  8. app.use(express.static(__dirname + '/public'))
  9.  
  10. app.use(function(req, res, next) {
  11. res.header("Access-Control-Allow-Origin", "*");
  12. res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  13. next()
  14. })
  15.  
  16. app.get('/', (request, response) => {
  17. response.render('index')
  18. })
  19.  
  20. app.listen(port, () => {
  21. console.log(`Server listening on port ${port}`)
  22. })
  23.  
  24. import $ from 'jquery';
  25.  
  26. function getLocation() {
  27. if ("geolocation" in navigator) {
  28. navigator.geolocation.getCurrentPosition(function(position) {
  29. fetchWeatherData(position.coords.latitude, position.coords.longitude)
  30. }, function(error) {
  31. //Aqui manejo los errores
  32. })
  33. } else {
  34. //Pendiente aun
  35. }
  36. }
  37.  
  38. function fetchWeatherData(latitude, longitude) {
  39. let URL = `https://api.darksky.net/forecast/bcce7da12ae098129b6c69b207e89ecb/${latitude},${longitude}`
  40. $.ajax(URL, {
  41. method: 'GET',
  42. dataType: 'json',
  43. beforeSend: function(request) {
  44. request.setRequestHeader("Access-Control-Allow-Origin", '*');
  45. },
  46. success: function(response) {
  47. console.log(response.data)
  48. }
  49. })
  50.  
  51. }
  52.  
  53. getLocation()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement