rx-bing-services

0.0.3 • Public • Published

RxBingServices

Reactive extensions for Bing location and mapping services

This package contains a suite of reactive extension APIs for Bing Map and Location based services: The goal of this package is providing a clean, well-defined API to help make it easier for developers to interact with Microsoft's most powerful services. These API's are built on top of the Reactive(Rx) framework, which helps manage and orcherstrate the asynchronous service calls to Bing. This Node module provides Bing service interfacing hooks for Spatial Data(whats around me), Location Search(where am I) and Navigation Directions(Take Me To). For more details on the underlying Bing Services, please visit Bing.Services.

<img src="https://cloud.githubusercontent.com/assets/7635865/9588268/4a0e9478-4ff5-11e5-9fb2-4fb959982881.jpg"width="600" height="300" />

Usage

To install this package, run npm install RxBingServices API Key Request.

var BingServices = require('RxBingServices');
import Rx from 'rx';

Check out the places around you by calling whats around me, including your current lat/long.

// Fetch the west village surroundings
var rsp = BingServices.whatsAroundMe({
  apiKey: 'place your API key here',
  location: '40.735803,-74.001374',
  top: 20,
  radius: 1
} , {
  // An unexpected error occurred.
  error: function (e){
    console.log('Received a validation error:\n', e);
  }
}).subscribe((rspSequence) => {
           Rx.Observable.from(BingServices.fromResponseToSpatialEntities(rspSequence))
                        .subscribe((location) => {
                            let entityType = BingServices.getEntityTypeDetails(location.EntityTypeID);
                            console.log(JSON.stringify(extend(true, {}, location, entityType)));
                        });
        },
        (error) => {
            console.log("There was an error: " + error);
        }
);

All services in this package will return a Rx observable, which is available for subscription. The subscribe will stream the response in an async fashion. If the request fails its validation request, then the clients error callback will be invoked with the details encapsulated in the error parameter. the client success or error callback depending on the status of the Bing call and response. In this example we're converting the response into an observable sequence, and merging the location details with the metadata details for each returned location.

API Reference

BingServices

All services are available within the BingServices module

BingServices.whatsAroundMe(options, errorCallback) => Observable

Bing Spatial Data Service: collects all entities around a specified geo location. This calls bing spatial data service as an observable, and uses Rx to subscribe to the response of nearby entities

Returns: An observable sequence. The table below describes the input parameters which this service supports.

Supported Input Parameters
Param Type Example Required Description Default
apiKey string 232edfdnfddf4450 Yes Your api access key to access bing spatial data services. This can be obtained at https://msdn.microsoft.com/en-us/library/ff428642.aspx None
location string 34.23245532,-40.47464 Yes The users latitude and longitude None
select string Latitude,Longitude,IsWiFiHotSpot,DisplayName No The selection fields from the bing spatial data source All/*
datasourceName string NAVTEQNA No The selection fields from the bing spatial data source NAVTEQNA
poiName string NavteqPOIs No The point of interest name NavteqPOIs
filter string StartsWith(PrimaryCity, Clear) eq true No The Odata filter for the bing spatial data query None
orberByClause string IsWheelchairAccessible No The Odata order by clause for the bing spatial data query None
top int 10 No Sets the max returned allowable results 20
radius int 1 Yes Spatial data filter radius(in kilometers) None

BingServices.fromResponseToSpatialEntities(response)

Function to convert a whatsAroundMe response to a structured Data Contract array. You can then use Rx.Observable.from to convert the response items to a structured data stream. The response data contract depends on the spatial data source you're requesting. You can even create your own spatial data source, and customize the geo-tagged schema. For more details on creating/publishing your own custom data source or the Microsoft supported public data sources check out https://msdn.microsoft.com/en-us/library/hh478189.aspx

BingServices.getEntityTypeDetails(entityTypeId)

Function to translate an spatial data returned entitytypeId to a data structure that's more descriptive and useful. This provides a description and icon word for a particular entity type. The icon word can be used to customize your own pushpin icon image, when leveraging the RxBingMaps visualization component.

BingServices.whereAmI(options, errorCallback) => Observable

Bing Location Data Service: Use the following service to get the location information associated with either a) latitude and longitude coordinates b) A query string i.e. 'The Space Needle' or '1600 Pennsylvania Ave'. This calls bing location data service and transforms the stream to an observable, and uses Rx to subscribe to the returned response location details.

Returns: An observable sequence. The table below describes the input parameters which this service supports.

Supported Input Parameters
Param Type Example Required Description Default
apiKey string 232edfdnfddf4450 Yes Your api access key to access bing data services. This can be obtained at https://msdn.microsoft.com/en-us/library/ff428642.aspx None
location string 34.23245532,-40.47464 Yes The users latitude and longitude None
Usage
var rsp = BingServices.whereAmI({
          apiKey: process.env.BING_API_KEY,
          location: "{0},{1}".format(latitude, longitude)
      } , {
        // An unexpected error occurred.
        error: function (e){
          console.log('Received a validation error:\n', e);
        }
      })

BingServices.fromResponeToLocationResources(response)

Function to convert a WhereAmI response to a structured Data Contract array. You can then use Rx.Observable.from to convert the response items to a structured data stream of location resources. To see the details of the data attributes for each location resource, check out the Bing API docs for the response of Location API https://msdn.microsoft.com/en-us/library/ff701725.aspx

Usage
Rx.Observable.from(BingServices.fromResponeToLocationResources(rspSequence))
                     .subscribe((location) => {
                         console.log("You are currently at Point: {0},{1} Address: {2}".format(location.point.coordinates[0], location.point.coordinates[1], location.name));
                     });

Readme

Keywords

none

Package Sidebar

Install

npm i rx-bing-services

Weekly Downloads

0

Version

0.0.3

License

MIT

Last publish

Collaborators

  • erikschlegel