Azure SDK for Java Reference Documentation

Current version is 1.0.0-beta.1, click here for the index

Azure Maps SDK Weather client library for Java

Azure Maps SDK Weather client library for Java.

This package contains the Azure Maps SDK Weather client library which contains Azure Maps Weather APIs. For documentation on how to use this package, please see Azure Maps Weather SDK for Java.

Source code | API reference documentation | REST API documentation | Product documentation | Samples

Documentation

Various documentation is available to help you get started

Getting started

Prerequisites

Adding the package to your product

<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-maps-weather</artifactId>
    <version>1.0.0-beta.1</version>
</dependency>

Azure Maps Libraries require a TokenCredential implementation for authentication and an HttpClient implementation for HTTP client.

Azure Identity package and Azure Core Netty HTTP package provide the default implementation.

Authentication

By default, Azure Active Directory token authentication depends on correct configure of following environment variables.

  • AZURE_CLIENT_ID for Azure client ID.
  • AZURE_TENANT_ID for Azure tenant ID.
  • AZURE_CLIENT_SECRET or AZURE_CLIENT_CERTIFICATE_PATH for client secret or client certificate.

In addition, Azure subscription ID can be configured via environment variable AZURE_SUBSCRIPTION_ID.

With above configuration, azure client can be authenticated by following code:

// Authenticates using Azure AD building a default credential
// This will look for AZURE_CLIENT_ID, AZURE_TENANT_ID, and AZURE_CLIENT_SECRET env variables
DefaultAzureCredential tokenCredential = new DefaultAzureCredentialBuilder().build();

// Creates a client
WeatherClient client = new WeatherClientBuilder()
    .credential(tokenCredential)
    .weatherClientId(System.getenv("MAPS_CLIENT_ID"))
    .buildClient();

The sample code assumes global Azure. Please change AzureEnvironment.AZURE variable if otherwise.

See Authentication for more options.

Key concepts

See API design for general introduction on design and key concepts on Azure Management Libraries.

Examples

Get Hourly Forecast

client.getHourlyForecast(new GeoPosition(-122.138874, 47.632346), null, 12, null);

Get Minute Forecast

client.getMinuteForecast(new GeoPosition(-122.138874, 47.632346), 15, null);

Get Minute Forecast

client.getQuarterDayForecast(new GeoPosition(-122.138874, 47.632346), null, 1, null);

Get Current Conditions

client.getCurrentConditions(new GeoPosition(-122.125679, 47.641268), 
    null, null, null, null);

Get Daily Forecast

client.getDailyForecast(new GeoPosition(30.0734812, 62.6490341), null, 5, null);

Get Weather Along Route

List<Waypoint> waypoints = Arrays.asList(
    new Waypoint(new GeoPosition(-77.037, 38.907), 0.0),
    new Waypoint(new GeoPosition(-77.009, 38.907), 10.0),
    new Waypoint(new GeoPosition(-76.928, 38.926), 20.0),
    new Waypoint(new GeoPosition(-76.852, 39.033), 30.0),
    new Waypoint(new GeoPosition(-76.732, 39.168), 40.0),
    new Waypoint(new GeoPosition(-76.634, 39.269), 50.0),
    new Waypoint(new GeoPosition(-76.612, 39.287), 60.0)
);
client.getWeatherAlongRoute(waypoints, "en");

Get Severe Weather Alerts

client.getSevereWeatherAlerts(new GeoPosition(-85.06431274043842, 30.324604968788467), null, true);

Get Daily Indices

client.getDailyIndices(new GeoPosition(-79.37849, 43.84745), null, null, null, 11);

Get Tropical Storm Active

client.getTropicalStormActive();

Get Tropical Storm Search

ActiveStormResult result = client.getTropicalStormActive();
if (result.getActiveStorms().size() > 0) {
    ActiveStorm storm = result.getActiveStorms().get(0);
    client.searchTropicalStorm(storm.getYear(), storm.getBasinId(), storm.getGovId());
}

Get Tropical Storm Forecast

ActiveStormResult result = client.getTropicalStormActive();
if (result.getActiveStorms().size() > 0) {
    ActiveStorm storm = result.getActiveStorms().get(0);
    TropicalStormForecastOptions forecastOptions = new TropicalStormForecastOptions(storm.getYear(),
        storm.getBasinId(), storm.getGovId())
        .setIncludeWindowGeometry(true);
    client.getTropicalStormForecast(forecastOptions);
}

Get Tropical Storm Locations

ActiveStormResult result = client.getTropicalStormActive();
if (result.getActiveStorms().size() > 0) {
    ActiveStorm storm = result.getActiveStorms().get(0);
    TropicalStormLocationOptions locationOptions = new TropicalStormLocationOptions(storm.getYear(),
        storm.getBasinId(), storm.getGovId());
    client.getTropicalStormLocations(locationOptions);
}

Get Current Air Quality

client.getCurrentAirQuality(
    new GeoPosition(-122.138874, 47.632346), "es", false);

Get Air Quality Daily Forecasts

client.getAirQualityDailyForecasts(
    new GeoPosition(-122.138874, 47.632346), "en", DailyDuration.TWO_DAYS);

Get Air Quality Hourly Forecasts

client.getAirQualityDailyForecasts(
    new GeoPosition(-122.138874, 47.632346), "en", DailyDuration.TWO_DAYS);

Get Daily Historical Actuals

LocalDate before = LocalDate.now().minusDays(30);
LocalDate today = LocalDate.now();
client.getDailyHistoricalActuals(new GeoPosition(30.0734812, 62.6490341), before, today, null);

Get Daily Historical Records

LocalDate before = LocalDate.now().minusDays(30);
LocalDate today = LocalDate.now();
client.getDailyHistoricalActuals(new GeoPosition(30.0734812, 62.6490341), before, today, null);

Get Daily Historical Normals

LocalDate before = LocalDate.now().minusDays(30);
LocalDate today = LocalDate.now();
client.getDailyHistoricalNormals(new GeoPosition(30.0734812, 62.6490341), before, today, null);

Troubleshooting

When you interact with the Azure Maps Services, errors returned by the Maps service correspond to the same HTTP status codes returned for REST API requests.

For example, if you search with an invalid coordinate, a error is returned, indicating "Bad Request".400

Next steps

Several Azure Maps Weather Java SDK samples are available to you in the SDK's GitHub repository. Azure Maps Weather Samples

Contributing

For details on contributing to this repository, see the contributing guide.

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request
Packages
Package
Description
Package containing the classes for WeatherClient.
Package containing the data models for WeatherClient.