npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nativescript-weather-api

v1.0.1

Published

Real-time weather information for any location on Earth, including over 200,000 cities.

Downloads

2

Readme

NativeScript Weather API

Real-time weather information for any location on Earth, including over 200,000 cities.

Installation

tns plugin add nativescript-weather-api

Permission

Android

To request access to location, you need to add the following line to your app's AndroidManifest.xml:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

iOS

You need to include the NSLocationWhenInUseUsageDescription key in Info.plist to enable geolocation when using the app.

Usage

This plugin uses the OpenWeather API to show weather information, so you need to create an account on https://openweathermap.org and get your key. Free accounts are allowed to perform 1,000,000 calls/month and 60 calls/minute.

Import the plugin

import { getWeather, dailyForecast, showWeather, getLocation } from 'nativescript-weather-api';

API calls

By geographic coordinates

When using coordinates, you can't pass the city and ZIP code parameters.

var temp;
var wind;

getLocation().then((location) => {

getWeather({

	key: "your_key",
	lat: location.latitude,
	lon: location.longitude,
	unit: "metric"

}).then(() => {

	var data = new showWeather();
	temp = data.temp;
	wind = data.wind;
});

});

By city name

When calling by city name, you can't pass the latitude, longitude, and ZIP code parameters.

var temp;
var wind;

getWeather({

	key: "your_key",
	city: "London",
	country: "GB"

}).then(() => {

	var data = new showWeather();
	temp = data.temp;
	wind = data.wind;
});

By ZIP code

This method doesn't seem to work with all countries. For example, the API didn't recognize ZIP codes from Brazil during my tests.

Don't pass the latitude, longitude, and city parameters.

var temp;
var wind;

getWeather({

	key: "your_key",
	zip_code: "90001",
	country: "US"

}).then(() => {

	var data = new showWeather();
	temp = data.temp;
	wind = data.wind;
});

Parameters

key - Your OpenWeather key. lat - Latitude. lon - Longitude. city - City name, e.g., Los Angeles. country - Country code, e.g., US, CA, GB. zip_code - Numeric or alphanumeric codes, e.g., 90001. unit - If you set it to metric, the temperature will be in Celsius and wind speed in meter/s. If you choose imperial, the temperature will be in Fahrenheit and wind speed in miles/h. If you don't set this parameter, Kelvin and meter/s are the standards. lang - The output language for the city name and description fields, e.g., en, pt_br, fr, es.

Identifiers

name - Location name. country - Country name. temp - Temperature. temp_min - Minimum temperature. temp_max - Maximum temperature. feels_like - Feels like temperature. wind - Wind speed. pressure - Pressure. humidity - Humidity. description - Weather description, e.g., clear sky. icon - Weather icon URL.

Daily forecast for 7 days

With only one call, you can get weather information for 7 days plus the current day.

var temp_min;
var temp_max;
var description;

getLocation().then((location) => {

dailyForecast({

	key: "your_key",
	lat: location.latitude,
	lon: location.longitude,
	unit: "metric"

}).then((data) => {

	temp_min = data.daily[0].temp.min;
	temp_max = data.daily[0].temp.max;
	description = data.daily[0].weather[0].description;
});

});

The dailyForecast function only accepts latitude and longitude to determine the location. In the example, we retrieved the minimum and maximum temperature and the weather description for the current day. If we wanted information for the following day, we'd change daily[0] to daily[1], and so on up to daily[7]. To see all the fields available besides the ones we used in this section, create an alert(JSON.stringify(data, null, 4)), but don't forget to remove it before building for production.

NS compatibility

Update your NS version to 8+, or you might get an error with the @nativescript/geolocation plugin.