Skip to content
Snippets Groups Projects
Commit 6589b9b2 authored by Alex Reisner's avatar Alex Reisner Committed by GitHub
Browse files

Merge pull request #1088 from aleemuddin13/master

Added LocationIQ provider
parents 3aba2516 6cae2500
No related branches found
No related tags found
No related merge requests found
...@@ -457,6 +457,17 @@ The [Google Places Details API](https://developers.google.com/places/documentati ...@@ -457,6 +457,17 @@ The [Google Places Details API](https://developers.google.com/places/documentati
* **Terms of Service**: http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy * **Terms of Service**: http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy
* **Limitations**: Please limit request rate to 1 per second and include your contact information in User-Agent headers (eg: `Geocoder.configure(:http_headers => { "User-Agent" => "your contact info" })`). [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://www.openstreetmap.org/copyright) * **Limitations**: Please limit request rate to 1 per second and include your contact information in User-Agent headers (eg: `Geocoder.configure(:http_headers => { "User-Agent" => "your contact info" })`). [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://www.openstreetmap.org/copyright)
#### LocationIQ (`:location_iq`)
* **API key**: required
* **Quota**: 6 request/second (30k req/day), then ability to purchase more
* **Region**: world
* **SSL support**: yes
* **Languages**: ?
* **Documentation**: http://locationiq.org/#docs
* **Terms of Service**: https://unwiredlabs.com/tos
* **Limitations**: [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://www.openstreetmap.org/copyright)
#### OpenCageData (`:opencagedata`) #### OpenCageData (`:opencagedata`)
* **API key**: required * **API key**: required
......
...@@ -23,6 +23,7 @@ module Geocoder ...@@ -23,6 +23,7 @@ module Geocoder
# #
def street_services def street_services
@street_services ||= [ @street_services ||= [
:location_iq,
:dstk, :dstk,
:esri, :esri,
:google, :google,
......
require 'geocoder/lookups/nominatim'
require "geocoder/results/location_iq"
module Geocoder::Lookup
class LocationIq < Nominatim
def name
"LocationIq"
end
def required_api_key_parts
["api_key"]
end
def query_url(query)
method = query.reverse_geocode? ? "reverse.php" : "search.php"
host = configuration[:host] || "locationiq.org/v1"
"#{protocol}://#{host}/#{method}?key=#{configuration.api_key}&" + url_query_string(query)
end
private
def results(query)
return [] unless doc = fetch_data(query)
if !doc.is_a?(Array) && doc['error'] =~ /Invalid\skey/
raise_error(Geocoder::InvalidApiKey, doc['error'])
end
doc.is_a?(Array) ? doc : [doc]
end
end
end
require 'geocoder/results/nominatim'
module Geocoder::Result
class LocationIq < Nominatim
end
end
\ No newline at end of file
{
"error": "Invalid key"
}
[
{
"place_id": "30632629",
"licence": "Data Copyright OpenStreetMap Contributors, Some Rights Reserved. CC-BY-SA 2.0.",
"osm_type": "way",
"osm_id": "24801588",
"boundingbox": [
"40.749828338623",
"40.7511596679688",
"-73.9943389892578",
"-73.9926528930664"
],
"polygonpoints": [
[
"-73.9943346",
"40.7503638"
],
[
"-73.9942745",
"40.7504158"
],
[
"-73.9942593",
"40.750629"
],
[
"-73.9941343",
"40.7508432"
],
[
"-73.9939794",
"40.7509703"
],
[
"-73.9938042",
"40.7510532"
],
[
"-73.9938025",
"40.7511311"
],
[
"-73.9936051",
"40.7511571"
],
[
"-73.9935673",
"40.751105"
],
[
"-73.9934095",
"40.7511089"
],
[
"-73.9931235",
"40.7510548"
],
[
"-73.9928863",
"40.7509311"
],
[
"-73.9928068",
"40.750949"
],
[
"-73.992721",
"40.7508515"
],
[
"-73.9927444",
"40.7507889"
],
[
"-73.9926693",
"40.7506457"
],
[
"-73.9926597",
"40.7503657"
],
[
"-73.9928305",
"40.7500953"
],
[
"-73.9929757",
"40.7499911"
],
[
"-73.9931281",
"40.7499238"
],
[
"-73.993133",
"40.7498631"
],
[
"-73.9932961",
"40.7498306"
],
[
"-73.9933664",
"40.7498742"
],
[
"-73.993471",
"40.7498701"
],
[
"-73.9938023",
"40.7499263"
],
[
"-73.9940703",
"40.7500756"
],
[
"-73.9941876",
"40.7502038"
],
[
"-73.9942831",
"40.7502142"
],
[
"-73.9943346",
"40.7503638"
]
],
"lat": "40.7504928941818",
"lon": "-73.993466492276",
"display_name": "Madison Square Garden, West 31st Street, Long Island City, New York City, New York, 10001, United States of America",
"class": "leisure",
"type": "stadium",
"address": {
"stadium": "Madison Square Garden",
"road": "West 31st Street",
"suburb": "Long Island City",
"city": "New York City",
"county": "New York",
"state": "New York",
"postcode": "10001",
"country": "United States of America",
"country_code": "us"
}
}
]
[ ]
<html>\n<head>\n<title>Bandwidth limit exceeded</title>\n</head>\n<body>\n<h1>Bandwidth limit exceeded</h1>\n\n<p>You have been temporarily blocked because you have been overusing OSM's geocoding service or because you have not provided sufficient identification of your application. This block will be automatically lifted after a while. Please take the time and adapt your scripts to reduce the number of requests and make sure that you send a valid UserAgent or Referer.</p>\n\n<p>For more information, consult the <a href=\"http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy\">usage policy</a> for the OSM Nominatim server.\n</body>\n</head>\n
...@@ -181,6 +181,14 @@ module Geocoder ...@@ -181,6 +181,14 @@ module Geocoder
end end
end end
require 'geocoder/lookups/location_iq'
class LocationIq
private
def fixture_prefix
"location_iq"
end
end
require 'geocoder/lookups/yandex' require 'geocoder/lookups/yandex'
class Yandex class Yandex
private private
......
# encoding: utf-8
require 'unit/lookups/nominatim_test'
require 'test_helper'
class LocationIq < NominatimTest
def setup
Geocoder.configure(lookup: :location_iq)
set_api_key!(:location_iq)
end
def test_url_contains_api_key
Geocoder.configure(location_iq: {api_key: "abc123"})
query = Geocoder::Query.new("Leadville, CO")
assert_equal "http://locationiq.org/v1/search.php?key=abc123&accept-language=en&addressdetails=1&format=json&q=Leadville%2C+CO", query.url
end
def test_raises_exception_with_invalid_api_key
Geocoder.configure(always_raise: [Geocoder::InvalidApiKey])
assert_raises Geocoder::InvalidApiKey do
Geocoder.search("invalid api key")
end
end
end
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