bing maps api wrapper
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin
lib
spec
.gitignore
.rspec
.travis.yml
Gemfile
LICENSE.txt
README.md
Rakefile
example.png
moscow.png
virtualearth.gemspec

README.md

Virtualearth Build Status

Before usage need creating a Bing Maps Key.

Bing maps api wrapper.

Installation

Add this line to your application's Gemfile:

gem 'virtualearth'

Usage

Initialize client with TOKEN.

vr = Virtualearth::Client.new(TOKEN)

Locations API

API references.

vr.locations(q: 'Москва')

=> [#<Virtualearth::Location:0x007fb733b6a8b8
  @address=
   #<Virtualearth::Address:0x007fb733b69dc8
    @address_line=nil,
    @admin_district="Moscow City",
    @admin_district2=nil,
    @country_region="Russia",
    @country_region_iso2=nil,
    @formatted_address="Moscow, Russia",
    @landmark=nil,
    @locality="Moscow",
    @match_codes=[],
    @neighborhood=nil,
    @postal_code=nil>,
  @bbox=#<Virtualearth::BoundingBox:0x007fb733b6a818 @east_longitude=38.6138687133789, @north_latitude=56.0980911254883, @south_latitude=55.4053268432617, @west_longitude=36.6221771240234>,
  @confidence="High",
  @entity_type="PopulatedPlace",
  @geocode_points=
   [#<Virtualearth::GeocodePoint:0x007fb733b689a0
     @calculation_method="Rooftop",
     @match_codes=[],
     @point=
      #<Virtualearth::Point:0x007fb733b691c0 @calculation_method=nil, @description=nil, @is_via=nil, @latitude=55.7569618225098, @location_identifier=nil, @longitude=37.6150093078613, @route_path_index=nil>,
     @usage_types=["Display"]>],
  @match_codes=["Ambiguous"],
  @name="Moscow, Russia",
  @point=
   #<Virtualearth::Point:0x007fb733b6a5e8 @calculation_method=nil, @description=nil, @is_via=nil, @latitude=55.7569618225098, @location_identifier=nil, @longitude=37.6150093078613, @route_path_index=nil>,
  @query_parse_values=[]>,
  #<Virtualearth::Location:0x007fb733b685b8

or simmilar

vr.locations_by_query('Москва')
=> [#<Virtualearth::Location:0x007fb73340d188
  @address=
   #<Virtualearth::Address:0x007fb73340c6c0
    @address_line=nil,
    @admin_district="Moscow City",
    @admin_district2=nil,
    @country_region="Russia",
    @country_region_iso2=nil,
    @formatted_address="Moscow, Russia",
    @landmark=nil,
    @locality="Moscow",
    @match_codes=[],
    @neighborhood=nil,
    @postal_code=nil>,
  @bbox=#<Virtualearth::BoundingBox:0x007fb73340d0e8 @east_longitude=38.6138687133789, @north_latitude=56.0980911254883, @south_latitude=55.4053268432617, @west_longitude=36.6221771240234>,
  @confidence="High",
  @entity_type="PopulatedPlace",
  @geocode_points=
   [#<Virtualearth::GeocodePoint:0x007fb7334072b0
     @calculation_method="Rooftop",
     @match_codes=[],
     @point=
      #<Virtualearth::Point:0x007fb733407aa8 @calculation_method=nil, @description=nil, @is_via=nil, @latitude=55.7569618225098, @location_identifier=nil, @longitude=37.6150093078613, @route_path_index=nil>,
     @usage_types=["Display"]>],
  @match_codes=["Ambiguous"],
  @name="Moscow, Russia",
  @point=
   #<Virtualearth::Point:0x007fb73340ceb8 @calculation_method=nil, @description=nil, @is_via=nil, @latitude=55.7569618225098, @location_identifier=nil, @longitude=37.6150093078613, @route_path_index=nil>,
  @query_parse_values=[]>,
 #<Virtualearth::Location:0x007fb733406ec8

or search by GEO point

vr.locations_by_point('55.7569618225098,37.6150093078613')
=> [#<Virtualearth::Location:0x007fb733b48bc8
  @address=
   #<Virtualearth::Address:0x007fb733b33e30
    @address_line="Tverskaya ulitsa",
    @admin_district="Central Federal District",
    @admin_district2="Moscow",
    @country_region="Russia",
    @country_region_iso2=nil,
    @formatted_address="Tverskaya ulitsa, Moscow, Russia, 125009",
    @landmark=nil,
    @locality="Moscow",
    @match_codes=[],
    @neighborhood=nil,
    @postal_code="125009">,
  @bbox=#<Virtualearth::BoundingBox:0x007fb733b48ad8 @east_longitude=37.61513, @north_latitude=55.75703, @south_latitude=55.75691, @west_longitude=37.61491>,
  @confidence="Medium",
  @entity_type="Address",
  @geocode_points=
   [#<Virtualearth::GeocodePoint:0x007fb733b32dc8
     @calculation_method="Interpolation",
     @match_codes=[],
     @point=#<Virtualearth::Point:0x007fb733b335e8 @calculation_method=nil, @description=nil, @is_via=nil, @latitude=55.756972, @location_identifier=nil, @longitude=37.6150148, @route_path_index=nil>,
     @usage_types=["Display", "Route"]>],
  @match_codes=["Good"],
  @name="Tverskaya ulitsa, Moscow, Russia, 125009",
  @point=#<Virtualearth::Point:0x007fb733b48830 @calculation_method=nil, @description=nil, @is_via=nil, @latitude=55.756972, @location_identifier=nil, @longitude=37.6150148, @route_path_index=nil>,
  @query_parse_values=[]>,
 #<Virtualearth::Location:0x007fb733b329e0

Elevations API

API references.

Elevations list

vr.elevations(points: '35.89431,-110.72522,35.89393,-110.72578,35.89374,-110.72606,35.89337,-110.72662')
=> [#<Virtualearth::Elevation:0x007fb8ab400018 @elevations=[1776, 1775, 1777, 1776], @zoom_level=14>]

Elevations polyline

vr.elevations_polyline(points: '35.89431,-110.72522,35.89393,-110.72578,35.89374,-110.72606,35.89337,-110.72662', heights: :ellipsoid, samples: 10)
=> [#<Virtualearth::Elevation:0x007fc6fc21c5a8 @elevations=[1753, 1752, 1752, 1752, 1752, 1754, 1754, 1754, 1754, 1753], @zoom_level=14>]

Elevations bounds

vr.elevations_bounds(bounds: '50.995391,-1.320763,51.000577,-1.311836', rows: 4, cols: 4)
=> [#<Virtualearth::Elevation:0x007fc6fc5e31a0 @elevations=[35, 39, 42, 41, 35, 37, 39, 43, 38, 37, 41, 40, 37, 41, 48, 49], @zoom_level=11>]

Imagery API

Imagery by area

params = { 'mapArea': '45.219,-122.325,47.610,-122.107', 'mapSize': '500,400' }

vr.imagery('AerialWithLabels', params).tap do |image|
  File.open('./example.png', 'w') do |file|
    file.write image.read
  end
end

Imagery by query

vr.imagery_by_query('CanvasDark', 'Москва', { 'mapSize': '500,400' }).tap do |image|
  File.open('./moscow.png', 'w') do |file|
    file.write image.read
  end
end

API references

Routes API

API references

Calculate a Route

API references.

vr.routes('wp.0': 'london', 'wp.1': 'leeds', 'avoid': 'minimizeTolls')
=> [#<Virtualearth::Route:0x007fc6fc5ba8e0
  @bbox=#<Virtualearth::BoundingBox:0x007fc6fc5ba840 @east_longitude=-0.1261, @north_latitude=53.7948, @south_latitude=51.49655, @west_longitude=-1.55768>,
  @distance_unit="Kilometer",
  @duration_unit="Second",
  @id=
   "v69,h872441760,i0,a2,cen-US,dAAAAAAAAAAA1,y0,s1,m1,o1,t4,wKQXdXtLASUBGsdzSakjAvw2~AxL8MMehfeMDAADgAe3G9T4A0~TG9uZG9uLCBMb25kb24sIFVuaXRlZCBLaW5nZG9t0~~~~v10,wL26jAbzlSkCthsQ9lr74vw2~AxL8MMcR9cEBAADgAQAAAD8A0~TGVlZHMsIFdlc3QgWW9ya3NoaXJlLCBVbml0ZWQgS2luZ2RvbQ2~~~~v10,k1",
  @route_legs=
   [#<Virtualearth::Leg:0x007fc6fc5ba598
     @actual_end=#<Virtualearth::Point:0x007fc6fc5ba4f8 @calculation_method=nil, @description=nil, @is_via=nil, @latitude=53.7948, @location_identifier=nil, @longitude=-1.54653, @route_path_index=nil>,
     @actual_start=#<Virtualearth::Point:0x007fc6fc5b9c88 @calculation_method=nil, @description=nil, @is_via=nil, @latitude=51.50642, @location_identifier=nil, @longitude=-0.12721, @route_path_index=nil>,
     @alternate_vias=[],
     @cost=0,
     @description="M1",
     @end_location=
      #<Virtualearth::Location:0x007fc6fc5b9238
       @address=
        #<Virtualearth::Address:0x007fc6fc5b86f8
         @address_line=nil,
         @admin_district="England",
         @admin_district2="West Yorkshire",
         @country_region="United Kingdom",
         @country_region_iso2=nil,
         @formatted_address="Leeds, West Yorkshire, United Kingdom",
         @landmark=nil,
         @locality="Leeds",
         @match_codes=[],
         @neighborhood=nil,
         @postal_code=nil>,
       @bbox=#<Virtualearth::BoundingBox:0x007fc6fc5b91c0 @east_longitude=-1.290352, @north_latitude=53.945873, @south_latitude=53.698967, @west_longitude=-1.800421>,
       @confidence="High",
       @entity_type="PopulatedPlace",
       @geocode_points=
        [#<Virtualearth::GeocodePoint:0x007fc6fc5b31a8
          @calculation_method="Rooftop",
          @match_codes=[],
          @point=#<Virtualearth::Point:0x007fc6fc5b3a40 @calculation_method=nil, @description=nil, @is_via=nil, @latitude=53.7948, @location_identifier=nil, @longitude=-1.54653, @route_path_index=nil>,
          @usage_types=["Display"]>],
       @match_codes=["Ambiguous"],
       @name="Leeds, West Yorkshire, United Kingdom",
       @point=#<Virtualearth::Point:0x007fc6fc5b8ef0 @calculation_method=nil, @description=nil, @is_via=nil, @latitude=53.7948, @location_identifier=nil, @longitude=-1.54653, @route_path_index=nil>,
       @query_parse_values=[]>,
     @end_time=nil,
     @itinerary_items=
      [#<Virtualearth::ItineraryItem:0x007fc6fc5b2d48
        @child_itinerary_items=[],
        @compass_direction="southeast",
        @details=
         [#<Virtualearth::Detail:0x007fc6fc5b2c80
           @compass_degrees=153,
           @end_path_indices=[6],
           @location_codes=["C07+07263", "C10+02229", "C07-07262", "C10-02228", "C07+37673", "C10N02228", "C10N51809", "C07P33179"],
           @maneuver_type="DepartStart",
           @mode="Driving",
           @names=["Whitehall"],
           @road_shield_request_parameters=
            #<Virtualearth::RoadShieldRequestParameters:0x007fc6fc5b2a50 @bucket=590501, @shields=[#<Virtualearth::Shield:0x007fc6fc5b2938 @labels=["A3212"], @road_shield_type=[2]>]>,
           @road_type="Arterial",
           @start_path_indices=[0]>],
        @exit="",

Driving routes

API references.

vr.driving_routes('wp.0': 'redmond,wa', 'wp.1': 'Issaquah,wa', 'avoid': :minimizeTolls)
=> [#<Virtualearth::Route:0x007fc6fc886858
  @bbox=#<Virtualearth::BoundingBox:0x007fc6fc8867b8 @east_longitude=-122.02333, @north_latitude=47.67859, @south_latitude=47.52995, @west_longitude=-122.18945>,
  @distance_unit="Kilometer",
  @duration_unit="Second",
  @id=
   "v69,h-1082882401,i0,a2,cen-US,dAAAAAAAAAAA1,y0,s1,m1,o1,t4,w71cBvtvWR0D4-e_Ba4hewA2~Aujb2OiBlTEBAADgAQAAgD8A0~UmVkbW9uZCwgV0E1~~~~v10,w5Pc2_dnDR0DBOo4fKoJewA2~Aujb2OixgT8BAADgAfLX_j4A0~SXNzYXF1YWgsIFdB0~~~~v10,k1",
  @route_legs=
   [#<Virtualearth::Leg:0x007fc6fc886510
     @actual_end=#<Virtualearth::Point:0x007fc6fc886470 @calculation_method=nil, @description=nil, @is_via=nil, @latitude=47.53009, @location_identifier=nil, @longitude=-122.033821, @route_path_index=nil>,
     @actual_start=#<Virtualearth::Point:0x007fc6fc885bb0 @calculation_method=nil, @description=nil, @is_via=nil, @latitude=47.67858, @location_identifier=nil, @longitude=-122.13146, @route_path_index=nil>,
     @alternate_vias=[],
     @cost=0,
     @description="WA-520 W, I-90 E",
     @end_location=
      #<Virtualearth::Location:0x007fc6fc8852c8
       @address=
        #<Virtualearth::Address:0x007fc6fc884760
         @address_line=nil,
         @admin_district="WA",
         @admin_district2="King",
         @country_region="United States",
         @country_region_iso2=nil,
         @formatted_address="Issaquah, WA",
         @landmark=nil,
         @locality="Issaquah",
         @match_codes=[],
         @neighborhood=nil,
         @postal_code=nil>,
       @bbox=#<Virtualearth::BoundingBox:0x007fc6fc885228 @east_longitude=-121.985748, @north_latitude=47.577374, @south_latitude=47.509083, @west_longitude=-122.100555>,
       @confidence="High",
       @entity_type="PopulatedPlace",
       @geocode_points=
        [#<Virtualearth::GeocodePoint:0x007fc6fc87f6c0
          @calculation_method="Rooftop",
          @match_codes=[],
          @point=#<Virtualearth::Point:0x007fc6fc87fee0 @calculation_method=nil, @description=nil, @is_via=nil, @latitude=47.53009, @location_identifier=nil, @longitude=-122.033821, @route_path_index=nil>,
          @usage_types=["Display"]>],
       @match_codes=["Good"],
       @name="Issaquah, WA",
       @point=#<Virtualearth::Point:0x007fc6fc884ff8 @calculation_method=nil, @description=nil, @is_via=nil, @latitude=47.53009, @location_identifier=nil, @longitude=-122.033821, @route_path_index=nil>,
       @query_parse_values=[]>,
     @end_time=nil,
     @itinerary_items=
      [#<Virtualearth::ItineraryItem:0x007fc6fc87f238

Walking routes

API references.

vr.walking_routes('wp.0': 'Eiffel Tower', 'wp.1': 'louvre museum', 'optmz': :distance)
=> [#<Virtualearth::Route:0x007fc6fda1c6d0
  @bbox=#<Virtualearth::BoundingBox:0x007fc6fda1c608 @east_longitude=2.33735, @north_latitude=48.86322, @south_latitude=48.85853, @west_longitude=2.29467>,
  @distance_unit="Kilometer",
  @duration_unit="Second",
  @id=
   "v69,h-989855539,i0,a0,cen-US,dAAAAAAAAAAA1,y0,s1,m2,o2,t0,wYOXQItttSEAlr84xIFsCQA2~AxL8MMfBJkMbAADgAf__fz8B0~RWlmZmVsIFRvd2VyLCBQYXJpcywgRnJhbmNl0~~~~v10,wMX2vIThuSEBWDi2yna8CQA2~AxL8MMcDWkUbAADgAczpDD8C0~TG91dnJlLCBQYXJpcywgRnJhbmNl0~~~~v10,k1",
  @route_legs=
   [#<Virtualearth::Leg:0x007fc6fda1c360
     @actual_end=#<Virtualearth::Point:0x007fc6fda1c2c0 @calculation_method=nil, @description=nil, @is_via=nil, @latitude=48.861178, @location_identifier=nil, @longitude=2.335647, @route_path_index=nil>,
     @actual_start=#<Virtualearth::Point:0x007fc6fda17c20 @calculation_method=nil, @description=nil, @is_via=nil, @latitude=48.85853, @location_identifier=nil, @longitude=2.29494, @route_path_index=nil>,
     @alternate_vias=[],
     @cost=0,
     @description="Quai Branly, Port de Solférino",
     @end_location=
      #<Virtualearth::Location:0x007fc6fda17270
       @address=
        #<Virtualearth::Address:0x007fc6fda164d8
         @address_line=nil,
         @admin_district="IdF",
         @admin_district2="Paris",
         @country_region="France",
         @country_region_iso2=nil,
         @formatted_address="Louvre, Paris, France",
         @landmark=nil,
         @locality=nil,
         @match_codes=[],
         @neighborhood=nil,
         @postal_code=nil>,
       @bbox=#<Virtualearth::BoundingBox:0x007fc6fda171d0 @east_longitude=2.343578, @north_latitude=48.864951, @south_latitude=48.857225, @west_longitude=2.327922>,
       @confidence="High",
       @entity_type="TouristStructure",
       @geocode_points=
        [#<Virtualearth::GeocodePoint:0x007fc6fda14ea8
          @calculation_method="Rooftop",
          @match_codes=[],
          @point=#<Virtualearth::Point:0x007fc6fda15858 @calculation_method=nil, @description=nil, @is_via=nil, @latitude=48.861088, @location_identifier=nil, @longitude=2.33575, @route_path_index=nil>,
          @usage_types=["Display"]>],
       @match_codes=["Good"],
       @name="Louvre, Paris, France",
       @point=#<Virtualearth::Point:0x007fc6fda16ed8 @calculation_method=nil, @description=nil, @is_via=nil, @latitude=48.861088, @location_identifier=nil, @longitude=2.33575, @route_path_index=nil>,
       @query_parse_values=[]>,
     @end_time=nil,
     @itinerary_items=
      [#<Virtualearth::ItineraryItem:0x007fc6fda14a48

Transit routes

API references.

vr.transit_routes('wp.0': 'Golden Gate Bridge', 'wp.1': 'Fishermans Wharf', 'timeType': 'Departure', 'dateTime': '3:00:00PM')
=> [#<Virtualearth::Route:0x007fc6fc4fd740
  @bbox=#<Virtualearth::BoundingBox:0x007fc6fc4fd448 @east_longitude=-122.40603, @north_latitude=37.812172, @south_latitude=37.798795, @west_longitude=-122.477756>,
  @distance_unit="Kilometer",
  @duration_unit="Second",
  @id=
   "v69,h1436225213,i0,a0,cen-US,dABinxNz91Ag1,y1,s1,m4,o1,t0,wjjulg_XnQkDlY3eBkp5ewA2~ASK6vqAhNnQCAADgAVA2yz4A0~R29sZGVuIEdhdGUgQnJpZGdlLCBDQQ2~~~~v10,wjc9k_zznQkAAAAAAAJpewA2~ASK6vqDDa3UCAADgAZQWCD8A0~RmlzaGVybWFuJ3MgV2hhcmYsIENB0~~~~v10,k1",
  @route_legs=
   [#<Virtualearth::Leg:0x007fc6fc4fc1d8
     @actual_end=#<Virtualearth::Point:0x007fc6fc4fc0c0 @calculation_method=nil, @description=nil, @is_via=nil, @latitude=37.806554, @location_identifier=nil, @longitude=-122.406251, @route_path_index=nil>,
     @actual_start=
      #<Virtualearth::Point:0x007fc6fc4f59c8 @calculation_method=nil, @description=nil, @is_via=nil, @latitude=37.812172, @location_identifier=nil, @longitude=-122.477756, @route_path_index=nil>,
     @alternate_vias=[],
     @cost=0,
     @description=nil,
     @end_location=
      #<Virtualearth::Location:0x007fc6fc4f4578
       @address=
        #<Virtualearth::Address:0x007fc6fc4ef258
         @address_line=nil,
         @admin_district="CA",
         @admin_district2="San Francisco",
         @country_region="United States",
         @country_region_iso2=nil,
         @formatted_address="Fisherman's Wharf, CA",
         @landmark=nil,
         @locality="San Francisco",
         @match_codes=[],
         @neighborhood=nil,
         @postal_code=nil>,
       @bbox=#<Virtualearth::BoundingBox:0x007fc6fc4f4460 @east_longitude=-122.403908, @north_latitude=37.81155, @south_latitude=37.804131, @west_longitude=-122.426537>,
       @confidence="High",
       @entity_type="Neighborhood",
       @geocode_points=
        [#<Virtualearth::GeocodePoint:0x007fc6fc4e6d60
          @calculation_method="Rooftop",
          @match_codes=[],
          @point=#<Virtualearth::Point:0x007fc6fc4e7e18 @calculation_method=nil, @description=nil, @is_via=nil, @latitude=37.806549, @location_identifier=nil, @longitude=-122.40625, @route_path_index=nil>,
          @usage_types=["Display"]>],
       @match_codes=["Ambiguous"],
       @name="Fisherman's Wharf, CA",
       @point=#<Virtualearth::Point:0x007fc6fc4f40c8 @calculation_method=nil, @description=nil, @is_via=nil, @latitude=37.806549, @location_identifier=nil, @longitude=-122.40625, @route_path_index=nil>,
       @query_parse_values=[]>,
     @end_time="/Date(1505688856000-0700)/",
     @itinerary_items=

Routes from major roads

API references.

vr.major_roads_routes(dest: '1 Microsoft Way Redmond WA 98052', exclude: 'routes')
=> [#<Virtualearth::Location:0x007fc6fc623188
  @address=nil,
  @bbox=nil,
  @confidence="High",
  @entity_type=nil,
  @geocode_points=[],
  @match_codes=[],
  @name="the north (on I-405 S)",
  @point=#<Virtualearth::Point:0x007fc6fc623098 @calculation_method=nil, @description=nil, @is_via=nil, @latitude=47.66317, @location_identifier=nil, @longitude=-122.18717, @route_path_index=nil>,
  @query_parse_values=[]>,
 #<Virtualearth::Location:0x007fc6fc6222b0
  @address=nil,
  @bbox=nil,
  @confidence="High",
  @entity_type=nil,
  @geocode_points=[],
  @match_codes=[],
  @name="the south (on I-405 N)",
  @point=#<Virtualearth::Point:0x007fc6fc6221c0 @calculation_method=nil, @description=nil, @is_via=nil, @latitude=47.61245, @location_identifier=nil, @longitude=-122.18853, @route_path_index=nil>,
  @query_parse_values=[]>,
 #<Virtualearth::Location:0x007fc6fc621388
  @address=nil,
  @bbox=nil,
  @confidence="High",
  @entity_type=nil,
  @geocode_points=[],
  @match_codes=[],
  @name="the west (on WA-520 E)",
  @point=#<Virtualearth::Point:0x007fc6fc621298 @calculation_method=nil, @description=nil, @is_via=nil, @latitude=47.636719, @location_identifier=nil, @longitude=-122.192789, @route_path_index=nil>,
  @query_parse_values=[]>,
 #<Virtualearth::Location:0x007fc6fc6205a0
  @address=nil,
  @bbox=nil,
  @confidence="High",
  @entity_type=nil,
  @geocode_points=[],
  @match_codes=[],
  @name="WA-520 W",
  @point=#<Virtualearth::Point:0x007fc6fc620488 @calculation_method=nil, @description=nil, @is_via=nil, @latitude=47.65992, @location_identifier=nil, @longitude=-122.1358, @route_path_index=nil>,
  @query_parse_values=[]>]

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/zinenko/virtualearth.