Skip to content
Snippets Groups Projects
Commit 4df7e463 authored by Alex Reisner's avatar Alex Reisner
Browse files

Merge commit '76035e33'

Conflicts:
	lib/geocoder.rb
parents 1949305b 76035e33
No related branches found
No related tags found
No related merge requests found
require 'geocoder/lookups/base'
require "geocoder/results/bing"
module Geocoder::Lookup
class Bing < Base
private # ---------------------------------------------------------------
def results(query, reverse = false)
return [] unless doc = fetch_data(query, reverse)
if doc['statusDescription'] == "OK"
return doc['resourceSets'].first['estimatedTotal'] > 0 ? doc['resourceSets'].first['resources'] : []
else
warn "Bing Geocoding API error: #{doc['statusCode']} (#{doc['statusDescription']})."
return []
end
end
def query_url(query, reverse = false)
params = {:key => Geocoder::Configuration.api_key}
params[:query] = query unless reverse
base_url = "http://dev.virtualearth.net/REST/v1/Locations"
url_tail = reverse ? "/#{query}?" : "?"
base_url + url_tail + hash_to_query(params)
end
end
end
require 'geocoder/results/base'
module Geocoder::Result
class Bing < Base
def address(format = :full)
data_address['formattedAddress']
end
def city
data_address['locality']
end
def country
data_address['countryRegion']
end
def country_code
# Bing does not return a contry code
""
end
def postal_code
data_address['postalCode']
end
def coordinates
data_coordinates['coordinates']
end
def data_address
@data['address']
end
def data_coordinates
@data['point']
end
def address_line
data_address['addressLine']
end
def state
data_address['adminDistrict']
end
def confidence
@data['confidence']
end
end
end
{
"authenticationResultCode":"ValidCredentials",
"brandLogoUri":"http:\/\/dev.virtualearth.net\/Branding\/logo_powered_by.png",
"copyright":"Copyright © 2011 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.",
"resourceSets":[
{
"estimatedTotal":1,
"resources":[
{
"__type":"Location:http:\/\/schemas.microsoft.com\/search\/local\/ws\/rest\/v1",
"bbox":[
40.744944289326668,
-74.002353921532631,
40.755675807595253,
-73.983625397086143
],
"name":"Madison Square Garden, NY",
"point":{
"type":"Point",
"coordinates":[
40.75031,
-73.99299
]
},
"address":{
"adminDistrict":"NY",
"countryRegion":"United States",
"formattedAddress":"Madison Square Garden, NY",
"locality":"New York"
},
"confidence":"High",
"entityType":"Stadium"
}
]
}
],
"statusCode":200,
"statusDescription":"OK",
"traceId":"55094ee53c8d45e789794014666328cd|CH1M001466|02.00.82.2800|CH1MSNVM001396, CH1MSNVM001370, CH1MSNVM001397"
}
\ No newline at end of file
{
"authenticationResultCode":"ValidCredentials",
"brandLogoUri":"http:\/\/dev.virtualearth.net\/Branding\/logo_powered_by.png",
"copyright":"Copyright © 2011 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.",
"resourceSets":[
{
"estimatedTotal":0,
"resources":[
]
}
],
"statusCode":200,
"statusDescription":"OK",
"traceId":"907b76a307bc49129a489de3d4c992ea|CH1M001463|02.00.82.2800|CH1MSNVM001383, CH1MSNVM001358, CH1MSNVM001397"
}
\ No newline at end of file
{
"authenticationResultCode":"ValidCredentials",
"brandLogoUri":"http:\/\/dev.virtualearth.net\/Branding\/logo_powered_by.png",
"copyright":"Copyright © 2011 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.",
"resourceSets":[
{
"estimatedTotal":1,
"resources":[
{
"__type":"Location:http:\/\/schemas.microsoft.com\/search\/local\/ws\/rest\/v1",
"bbox":[
45.419835111675845,
-75.683656128790716,
45.4275605468172,
-75.66898098334994
],
"name":"291 Rue Somerset E, Ottawa, ON, K1N",
"point":{
"type":"Point",
"coordinates":[
45.423697829246521,
-75.676318556070328
]
},
"address":{
"addressLine":"291 Rue Somerset E",
"adminDistrict":"ON",
"countryRegion":"Canada",
"formattedAddress":"291 Rue Somerset E, Ottawa, ON, K1N",
"locality":"Ottawa",
"postalCode":"K1N"
},
"confidence":"Medium",
"entityType":"Address"
}
]
}
],
"statusCode":200,
"statusDescription":"OK",
"traceId":"27bd5ed659e64ba6970c4144f1d4ea94|CH1M001470|02.00.82.2800|CH1MSNVM001396, CH1MSNVM001374"
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment