Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var geocoder;
- window.onload = load;
- function load() {
- geocoder = new google.maps.Geocoder();
- console.log(localStorage.weatherText);
- getWeather();
- }
- function getWeather() {
- if (navigator.geolocation) {
- navigator.geolocation.getCurrentPosition(loadWeatherByPos, locError);
- }
- }
- function getCityName(lat, lng) {
- var latlng = new google.maps.LatLng(lat, lng);
- geocoder.geocode({
- 'latLng': latlng
- }, function (results, status) {
- if (status == google.maps.GeocoderStatus.OK) {
- console.log(results);
- if (results[1]) {
- console.log("City name: " + results[0].address_components[1].short_name + " " + results[0].address_components[1].long_name);
- console.log("Province name: " + results[0].address_components[3].short_name + " " + results[0].address_components[3].long_name);
- } else {
- alert("No results found");
- }
- } else {
- alert("Geocoder failed due to: " + status);
- }
- });
- }
- function loadWeatherByPos(position) {
- var lat = position.coords.latitude;
- var lon = position.coords.longitude;
- getCityName(lat, lon);
- }
- function loadWeather(location, woeid) {
- $.simpleWeather({
- location: location,
- woeid: woeid,
- unit: 'c',
- success: function (weather) {
- var html = '<h2><i class="icon-' + weather.code + '"></i> ' + weather.temp + '°' + weather.units.temp + '</h2>';
- html += '<ul><li>' + weather.city + ', ' + weather.region + '</li>';
- html += '<li class="currently">' + weather.currently + '</li>';
- html += '<li>' + weather.wind.direction + ' ' + weather.wind.speed + ' ' + weather.units.speed + '</li></ul>';
- $("#weather").html(html);
- },
- error: function (error) {
- console.log(error);
- $("#weather").html('<p>Error something went wrong. Check the console...?</p>');
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement