diff --git a/.travis.yml b/.travis.yml index bb325f3f9..8aa85f633 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,17 @@ language: ruby +cache: bundler sudo: false + +services: + - postgresql + - mysql +before_script: + - psql -c 'create database geocoder_test;' -U postgres + +before_install: + - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true + - gem install bundler -v '< 2' + env: global: - JRUBY_OPTS=--2.0 @@ -10,49 +22,38 @@ env: - DB=postgres - DB=mysql rvm: - - 1.9.3 - 2.0.0 - - 2.1.2 - - 2.2.2 - - 2.3.0 + - 2.1.10 + - 2.2.10 + - 2.3.7 + - 2.4.4 + - 2.5.1 - jruby-19mode gemfile: - Gemfile - - gemfiles/Gemfile.ruby1.9.3 - - gemfiles/Gemfile.rails3.2 - gemfiles/Gemfile.rails4.1 - gemfiles/Gemfile.rails5.0 matrix: exclude: - - rvm: 1.9.3 - gemfile: Gemfile - - rvm: 1.9.3 - gemfile: gemfiles/Gemfile.rails3.2 - - rvm: 1.9.3 - gemfile: gemfiles/Gemfile.rails4.1 - - rvm: 1.9.3 - gemfile: gemfiles/Gemfile.rails5.0 - - env: DB= - gemfile: gemfiles/Gemfile.rails3.2 - env: DB= gemfile: gemfiles/Gemfile.rails4.1 - env: DB= gemfile: gemfiles/Gemfile.rails5.0 - rvm: 2.0.0 - gemfile: gemfiles/Gemfile.ruby1.9.3 + gemfile: Gemfile - rvm: 2.0.0 gemfile: gemfiles/Gemfile.rails5.0 - - rvm: 2.1.2 - gemfile: gemfiles/Gemfile.ruby1.9.3 - - rvm: 2.1.2 + - rvm: 2.1.10 + gemfile: Gemfile + - rvm: 2.1.10 gemfile: gemfiles/Gemfile.rails5.0 - - rvm: 2.2.2 - gemfile: gemfiles/Gemfile.ruby1.9.3 - - rvm: jruby-19mode - gemfile: gemfiles/Gemfile.ruby1.9.3 - - rvm: 2.3.0 - gemfile: gemfiles/Gemfile.ruby1.9.3 + - rvm: 2.4.4 + gemfile: gemfiles/Gemfile.rails4.1 + - rvm: 2.5.1 + gemfile: gemfiles/Gemfile.rails4.1 - rvm: jruby-19mode gemfile: gemfiles/Gemfile.rails5.0 + - rvm: jruby-19mode + gemfile: gemfiles/Gemfile.rails4.1 - env: DB=sqlite USE_SQLITE_EXT=1 rvm: jruby-19mode diff --git a/CHANGELOG.md b/CHANGELOG.md index 45f2b21a4..faa88bfd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,67 @@ Changelog Major changes to Geocoder for each release. Please see the Git log for complete list of changes. +1.6.3 (2020 Apr 30) +------------------- +* Update URL for :telize lookup (thanks github.com/alexwalling). +* Fix bug parsing IPv6 with port (thanks github.com/gdomingu). + +1.6.2 (2020 Mar 16) +------------------- +* Add support for :nationaal_georegister_nl lookup (thanks github.com/opensourceame). +* Add support for :uk_ordnance_survey_names lookup (thanks github.com/pezholio). +* Refactor and fix bugs in Yandex lookup (thanks github.com/iarie and stereodenis). + +1.6.1 (2020 Jan 23) +------------------- +* Sanitize lat/lon values passed to within_bounding_box to prevent SQL injection. + +1.6.0 (2020 Jan 6) +------------------- +* Drop support for Rails 3.x. +* Add support for :osmnames lookup (thanks github.com/zacviandier). +* Add support for :ipgeolocation IP lookup (thanks github.com/ahsannawaz111). + +1.5.2 (2019 Oct 3) +------------------- +* Add support for :ipregistry lookup (thanks github.com/ipregistry). +* Various fixes for Yandex lookup. + +1.5.1 (2019 Jan 23) +------------------- +* Add support for :tencent lookup (thanks github.com/Anders-E). +* Add support for :smarty_streets international API (thanks github.com/ankane). +* Remove :mapzen lookup. + +1.5.0 (2018 Jul 31) +------------------- +* Drop support for Ruby <2.0. +* Change default street address lookup from :google to :nominatim. +* Cache keys no longer include API credentials. This means many entries in existing cache implementations will be invalidated. +* Test lookup fixtures should now return `coordinates` and NOT `latitude`/`longitude` attributes (see #1258). This may break some people's tests. +* Add support for :ip2location lookup (thanks github.com/ip2location). +* Remove :ovi and :okf lookups. + +1.4.9 (2018 May 27) +------------------- +* Fix regression in :geoip2 lookup. +* Add support for Postcodes.io lookup (thanks github.com/sledge909). + +1.4.8 (2018 May 21) +------------------- +* Change default IP address lookup from :freegeoip to :ipinfo_io. +* Add support for :ipstack lookup (thanks github.com/Heath101). +* Fix incompatibility with redis-rb gem v4.0. + +1.4.7 (2018 Mar 13) +------------------- +* Allow HTTP protocol for Nominatim. + +1.4.6 (2018 Feb 28) +------------------- +* Add support for :ipdata_co lookup (thanks github.com/roschaefer). +* Update for Rails 5.2 compatibility (thanks github.com/stevenharman). + 1.4.5 (2017 Nov 29) ------------------- * Add support for :pickpoint lookup (thanks github.com/cylon-v). diff --git a/Gemfile b/Gemfile index 128b94fda..02d9c6bf1 100644 --- a/Gemfile +++ b/Gemfile @@ -2,15 +2,13 @@ source "https://rubygems.org" group :development, :test do gem 'rake' - gem 'mongoid', '2.6.0' + gem 'mongoid' gem 'bson_ext', platforms: :ruby gem 'geoip' gem 'rubyzip' - gem 'rails' + gem 'rails', '~>5.1.0' gem 'test-unit' # needed for Ruby >=2.2.0 - gem 'byebug', platforms: :mri - platforms :jruby do gem 'jruby-openssl' gem 'jgeoip' @@ -24,14 +22,14 @@ end group :test do platforms :ruby, :mswin, :mingw do - gem 'sqlite3' + gem 'sqlite3', '~> 1.4.2' gem 'sqlite_ext', '~> 1.5.0' end gem 'webmock' platforms :ruby do - gem 'pg' + gem 'pg', '~> 0.11' gem 'mysql2', '~> 0.3.11' end diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index 013f2faf8..59fa0ffc8 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -17,3 +17,4 @@ BEFORE POSTING AN ISSUE, PLEASE MAKE SURE THE PROBLEM IS NOT ADDRESSED IN THE RE * Geocoder version: * Rails version: * Database (if applicable): +* Lookup (if applicable): diff --git a/LICENSE b/LICENSE index 767580ccd..21dd3a0a2 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2009-11 Alex Reisner +Copyright (c) 2009-2020 Alex Reisner Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/README.md b/README.md index 232a2dd61..27c8b7010 100644 --- a/README.md +++ b/README.md @@ -1,137 +1,178 @@ Geocoder ======== -Geocoder is a complete geocoding solution for Ruby. With Rails, it adds geocoding (by street or IP address), reverse geocoding (finding street address based on given coordinates), and distance queries. It's as simple as calling `geocode` on your objects, and then using a scope like `Venue.near("Billings, MT")`. +**Complete geocoding solution for Ruby.** -_Please note that this README is for the current `HEAD` and may document features not present in the latest gem release. For this reason, you may want to instead view the README for your [particular version](https://github.com/alexreisner/geocoder/releases)._ +[![Gem Version](https://badge.fury.io/rb/geocoder.svg)](http://badge.fury.io/rb/geocoder) +[![Code Climate](https://codeclimate.com/github/alexreisner/geocoder/badges/gpa.svg)](https://codeclimate.com/github/alexreisner/geocoder) +[![Build Status](https://travis-ci.org/alexreisner/geocoder.svg?branch=master)](https://travis-ci.org/alexreisner/geocoder) +Key features: -Compatibility -------------- +* Forward and reverse geocoding. +* IP address geocoding. +* Connects to more than 40 APIs worldwide. +* Performance-enhancing features like caching. +* Integrates with ActiveRecord and Mongoid. +* Basic geospatial queries: search within radius (or rectangle, or ring). -* Supports multiple Ruby versions: Ruby 1.9.3, 2.x, and JRuby. -* Supports multiple databases: MySQL, PostgreSQL, SQLite, and MongoDB (1.7.0 and higher). -* Supports Rails 3, 4, and 5. If you need to use it with Rails 2 please see the `rails2` branch (no longer maintained, limited feature set). -* Works very well outside of Rails, you just need to install either the `json` (for MRI) or `json_pure` (for JRuby) gem. +Compatibility: +* Ruby versions: 2.x, and JRuby. +* Databases: MySQL, PostgreSQL, SQLite, and MongoDB. +* Rails: 4, 5, and 6. +* Works outside of Rails with the `json` (for MRI) or `json_pure` (for JRuby) gem. -Note on Rails 4.1 and Greater ------------------------------ - -Due to [a change in ActiveRecord's `count` method](https://github.com/rails/rails/pull/10710) you will need to use `count(:all)` to explicitly count all columns ("*") when using a `near` scope. Using `near` and calling `count` with no argument will cause exceptions in many cases. +Table of Contents +----------------- -Installation ------------- +Basic Features: -Install Geocoder like any other Ruby gem: +* [Basic Search](#basic-search) +* [Geocoding Objects](#geocoding-objects) +* [Geospatial Database Queries](#geospatial-database-queries) +* [Geocoding HTTP Requests](#geocoding-http-requests) +* [Geocoding Service ("Lookup") Configuration](#geocoding-service-lookup-configuration) - gem install geocoder +Advanced Features: -Or, if you're using Rails/Bundler, add this to your Gemfile: +* [Performance and Optimization](#performance-and-optimization) +* [Advanced Model Configuration](#advanced-model-configuration) +* [Advanced Database Queries](#advanced-database-queries) +* [Geospatial Calculations](#geospatial-calculations) +* [Batch Geocoding](#batch-geocoding) +* [Testing](#testing) +* [Error Handling](#error-handling) +* [Command Line Interface](#command-line-interface) - gem 'geocoder' +The Rest: -and run at the command prompt: +* [Technical Discussions](#technical-discussions) +* [Troubleshooting](#troubleshooting) +* [Known Issues](#known-issues) +* [Reporting Issues](#reporting-issues) +* [Contributing](#contributing) - bundle install +See Also: +* [Guide to Geocoding APIs](https://github.com/alexreisner/geocoder/blob/master/README_API_GUIDE.md) (formerly part of this README) -Object Geocoding ----------------- -### ActiveRecord +Basic Search +------------ -Your model must have two attributes (database columns) for storing latitude and longitude coordinates. By default they should be called `latitude` and `longitude` but this can be changed (see "Model Configuration" below): +In its simplest form, Geocoder takes an address and searches for its latitude/longitude coordinates: - rails generate migration AddLatitudeAndLongitudeToModel latitude:float longitude:float - rake db:migrate + results = Geocoder.search("Paris") + results.first.coordinates + => [48.856614, 2.3522219] # latitude and longitude -For geocoding, your model must provide a method that returns an address. This can be a single attribute, but it can also be a method that returns a string assembled from different attributes (eg: `city`, `state`, and `country`). +The reverse is possible too. Given coordinates, it finds an address: -Next, your model must tell Geocoder which method returns your object's geocodable address: + results = Geocoder.search([48.856614, 2.3522219]) + results.first.address + => "Hôtel de Ville, 75004 Paris, France" - geocoded_by :full_street_address # can also be an IP address - after_validation :geocode # auto-fetch coordinates +You can also look up the location of an IP addresses: -For reverse geocoding, tell Geocoder which attributes store latitude and longitude: + results = Geocoder.search("172.56.21.89") + results.first.coordinates + => [30.267153, -97.7430608] + results.first.country + => "United States" - reverse_geocoded_by :latitude, :longitude - after_validation :reverse_geocode # auto-fetch address +**The success and accuracy of geocoding depends entirely on the API being used to do these lookups.** Most queries work fairly well with the default configuration, but every application has different needs and every API has its particular strengths and weaknesses. If you need better coverage for your application you'll want to get familiar with the large number of supported APIs, listed in the [API Guide](https://github.com/alexreisner/geocoder/blob/master/README_API_GUIDE.md). -### Mongoid -First, your model must have an array field for storing coordinates: +Geocoding Objects +----------------- - field :coordinates, :type => Array +To automatically geocode your objects: -You may also want an address field, like this: +**1.** Your model must provide a method that returns an address to geocode. This can be a single attribute, but it can also be a method that returns a string assembled from different attributes (eg: `city`, `state`, and `country`). For example, if your model has `street`, `city`, `state`, and `country` attributes you might do something like this: - field :address + def address + [street, city, state, country].compact.join(', ') + end -but if you store address components (city, state, country, etc) in separate fields you can instead define a method called `address` that combines them into a single string which will be used to query the geocoding service. +**2.** Your model must have a way to store latitude/longitude coordinates. With ActiveRecord, add two attributes/columns (of type float or decimal) called `latitude` and `longitude`. For MongoDB, use a single field (of type Array) called `coordinates` (i.e., `field :coordinates, type: Array`). (See [Advanced Model Configuration](#advanced-model-configuration) for using different attribute names.) -Once your fields are defined, include the `Geocoder::Model::Mongoid` module and then call `geocoded_by`: +**3.** In your model, tell geocoder where to find the object's address: - include Geocoder::Model::Mongoid - geocoded_by :address # can also be an IP address - after_validation :geocode # auto-fetch coordinates + geocoded_by :address -Reverse geocoding is similar: +This adds a `geocode` method which you can invoke via callback: - include Geocoder::Model::Mongoid - reverse_geocoded_by :coordinates - after_validation :reverse_geocode # auto-fetch address + after_validation :geocode -Once you've set up your model you'll need to create the necessary spatial indices in your database: +Reverse geocoding (given lat/lon coordinates, find an address) is similar: - rake db:mongoid:create_indexes + reverse_geocoded_by :latitude, :longitude + after_validation :reverse_geocode -Be sure to read _Latitude/Longitude Order_ in the _Notes on MongoDB_ section below on how to properly retrieve latitude/longitude coordinates from your objects. +With any geocoded objects, you can do the following: -### MongoMapper + obj.distance_to([43.9,-98.6]) # distance from obj to point + obj.bearing_to([43.9,-98.6]) # bearing from obj to point + obj.bearing_from(obj2) # bearing from obj2 to obj -MongoMapper is very similar to Mongoid, just be sure to include `Geocoder::Model::MongoMapper`. +The `bearing_from/to` methods take a single argument which can be: a `[lat,lon]` array, a geocoded object, or a geocodable address (string). The `distance_from/to` methods also take a units argument (`:mi`, `:km`, or `:nm` for nautical miles). See [Distance and Bearing](#distance-and-bearing) below for more info. -### Mongo Indices +### One More Thing for MongoDB! -By default, the methods `geocoded_by` and `reverse_geocoded_by` create a geospatial index. You can avoid index creation with the `:skip_index option`, for example: +Before you can call `geocoded_by` you'll need to include the necessary module using one of the following: include Geocoder::Model::Mongoid - geocoded_by :address, :skip_index => true + include Geocoder::Model::MongoMapper -### Bulk Geocoding +### Latitude/Longitude Order in MongoDB -If you have just added geocoding to an existing application with a lot of objects, you can use this Rake task to geocode them all: +Everywhere coordinates are passed to methods as two-element arrays, Geocoder expects them to be in the order: `[lat, lon]`. However, as per [the GeoJSON spec](http://geojson.org/geojson-spec.html#positions), MongoDB requires that coordinates be stored longitude-first (`[lon, lat]`), so internally they are stored "backwards." Geocoder's methods attempt to hide this, so calling `obj.to_coordinates` (a method added to the object by Geocoder via `geocoded_by`) returns coordinates in the conventional order: - rake geocode:all CLASS=YourModel + obj.to_coordinates # => [37.7941013, -122.3951096] # [lat, lon] -If you need reverse geocoding instead, call the task with REVERSE=true: +whereas calling the object's coordinates attribute directly (`obj.coordinates` by default) returns the internal representation which is probably the reverse of what you want: - rake geocode:all CLASS=YourModel REVERSE=true + obj.coordinates # => [-122.3951096, 37.7941013] # [lon, lat] -Geocoder will print warnings if you exceed the rate limit for your geocoding service. Some services — Google notably — enforce a per-second limit in addition to a per-day limit. To avoid exceeding the per-second limit, you can add a `SLEEP` option to pause between requests for a given amount of time. You can also load objects in batches to save memory, for example: +So, be careful. - rake geocode:all CLASS=YourModel SLEEP=0.25 BATCH=100 +### Use Outside of Rails -To avoid per-day limit issues (for example if you are trying to geocode thousands of objects and don't want to reach the limit), you can add a `LIMIT` option. Warning: This will ignore the `BATCH` value if provided. +To use Geocoder with ActiveRecord and a framework other than Rails (like Sinatra or Padrino), you will need to add this in your model before calling Geocoder methods: - rake geocode:all CLASS=YourModel LIMIT=1000 + extend Geocoder::Model::ActiveRecord -### Avoiding Unnecessary API Requests -Geocoding only needs to be performed under certain conditions. To avoid unnecessary work (and quota usage) you will probably want to geocode an object only when: +Geospatial Database Queries +--------------------------- -* an address is present -* the address has been changed since last save (or it has never been saved) +### For ActiveRecord models: -The exact code will vary depending on the method you use for your geocodable string, but it would be something like this: +To find objects by location, use the following scopes: - after_validation :geocode, if: ->(obj){ obj.address.present? and obj.address_changed? } + Venue.near('Omaha, NE, US') # venues within 20 miles of Omaha + Venue.near([40.71, -100.23], 50) # venues within 50 miles of a point + Venue.near([40.71, -100.23], 50, units: :km) # venues within 50 kilometres of a point + Venue.geocoded # venues with coordinates + Venue.not_geocoded # venues without coordinates +With geocoded objects you can do things like this: -Request Geocoding by IP Address -------------------------------- + if obj.geocoded? + obj.nearbys(30) # other objects within 30 miles + obj.distance_from([40.714,-100.234]) # distance from arbitrary point to object + obj.bearing_to("Paris, France") # direction from object to arbitrary point + end + +### For MongoDB-backed models: + +Please do not use Geocoder's `near` method. Instead use MongoDB's built-in [geospatial query language](https://docs.mongodb.org/manual/reference/command/geoNear/), which is faster. Mongoid also provides [a DSL](http://mongoid.github.io/en/mongoid/docs/querying.html#geo_near) for geospatial queries. + + +Geocoding HTTP Requests +----------------------- Geocoder adds `location` and `safe_location` methods to the standard `Rack::Request` object so you can easily look up the location of any HTTP request by IP address. For example, in a Rails controller or a Sinatra app: @@ -140,164 +181,181 @@ Geocoder adds `location` and `safe_location` methods to the standard `Rack::Requ **The `location` method is vulnerable to trivial IP address spoofing via HTTP headers.** If that's a problem for your application, use `safe_location` instead, but be aware that `safe_location` will *not* try to trace a request's originating IP through proxy headers; you will instead get the location of the last proxy the request passed through, if any (excepting any proxies you have explicitly whitelisted in your Rack config). -Note that these methods will usually return `nil` in your test and development environments because things like "localhost" and "0.0.0.0" are not an Internet IP addresses. +Note that these methods will usually return `nil` in test and development environments because things like "localhost" and "0.0.0.0" are not geocodable IP addresses. -See _Advanced Geocoding_ below for more information about `Geocoder::Result` objects. +Geocoding Service ("Lookup") Configuration +------------------------------------------ -Location-Aware Database Queries -------------------------------- +Geocoder supports a variety of street and IP address geocoding services. The default lookups are `:nominatim` for street addresses and `:ipinfo_io` for IP addresses. Please see the [API Guide](https://github.com/alexreisner/geocoder/blob/master/README_API_GUIDE.md) for details on specific geocoding services (not all settings are supported by all services). -### For Mongo-backed models: +To create a Rails initializer with sample configuration: -Please use MongoDB's [geospatial query language](https://docs.mongodb.org/manual/reference/command/geoNear/). Mongoid also provides [a DSL](http://mongoid.github.io/en/mongoid/docs/querying.html#geo_near) for doing near queries. + rails generate geocoder:config -### For ActiveRecord models: +Some common options are: -To find objects by location, use the following scopes: + # config/initializers/geocoder.rb + Geocoder.configure( - Venue.near('Omaha, NE, US', 20) # venues within 20 miles of Omaha - Venue.near([40.71, -100.23], 20) # venues within 20 miles of a point - Venue.near([40.71, -100.23], 20, :units => :km) - # venues within 20 kilometres of a point - Venue.geocoded # venues with coordinates - Venue.not_geocoded # venues without coordinates + # street address geocoding service (default :nominatim) + lookup: :yandex, -by default, objects are ordered by distance. To remove the ORDER BY clause use the following: + # IP address geocoding service (default :ipinfo_io) + ip_lookup: :maxmind, - Venue.near('Omaha', 20, :order => false) + # to use an API key: + api_key: "...", -With geocoded objects you can do things like this: + # geocoding service request timeout, in seconds (default 3): + timeout: 5, - if obj.geocoded? - obj.nearbys(30) # other objects within 30 miles - obj.distance_from([40.714,-100.234]) # distance from arbitrary point to object - obj.bearing_to("Paris, France") # direction from object to arbitrary point - end + # set default units to kilometers: + units: :km, -Some utility methods are also available: + # caching (see [below](#caching) for details): + cache: Redis.new, + cache_prefix: "..." - # look up coordinates of some location (like searching Google Maps) - Geocoder.coordinates("25 Main St, Cooperstown, NY") - => [42.700149, -74.922767] + ) - # distance between Eiffel Tower and Empire State Building - Geocoder::Calculations.distance_between([47.858205,2.294359], [40.748433,-73.985655]) - => 3619.77359999382 # in configured units (default miles) +Please see [`lib/geocoder/configuration.rb`](https://github.com/alexreisner/geocoder/blob/master/lib/geocoder/configuration.rb) for a complete list of configuration options. Additionally, some lookups have their own special configuration options which are directly supported by Geocoder. For example, to specify a value for Google's `bounds` parameter: - # find the geographic center (aka center of gravity) of objects or points - Geocoder::Calculations.geographic_center([city1, city2, [40.22,-73.99], city4]) - => [35.14968, -90.048929] + # with Google: + Geocoder.search("Middletown", bounds: [[40.6,-77.9], [39.9,-75.9]]) -Please see the code for more methods and detailed information about arguments (eg, working with kilometers). +Please see the [source code for each lookup](https://github.com/alexreisner/geocoder/tree/master/lib/geocoder/lookups) to learn about directly supported parameters. Parameters which are not directly supported can be specified using the `:params` option, which appends options to the query string of the geocoding request. For example: + # Nominatim's `countrycodes` parameter: + Geocoder.search("Rome", params: {countrycodes: "us,ca"}) -Distance and Bearing --------------------- + # Google's `region` parameter: + Geocoder.search("Rome", params: {region: "..."}) -When you run a location-aware query the returned objects have two attributes added to them (only w/ ActiveRecord): +### Configuring Multiple Services -* `obj.distance` - number of miles from the search point to this object -* `obj.bearing` - direction from the search point to this object +You can configure multiple geocoding services at once by using the service's name as a key for a sub-configuration hash, like this: -Results are automatically sorted by distance from the search point, closest to farthest. Bearing is given as a number of clockwise degrees from due north, for example: + Geocoder.configure( -* `0` - due north -* `180` - due south -* `90` - due east -* `270` - due west -* `230.1` - southwest -* `359.9` - almost due north + timeout: 2, + cache: Redis.new, -You can convert these numbers to compass point names by using the utility method provided: + yandex: { + api_key: "...", + timeout: 5 + }, - Geocoder::Calculations.compass_point(355) # => "N" - Geocoder::Calculations.compass_point(45) # => "NE" - Geocoder::Calculations.compass_point(208) # => "SW" + baidu: { + api_key: "..." + }, -_Note: when using SQLite `distance` and `bearing` values are provided for interface consistency only. They are not very accurate._ + maxmind: { + api_key: "...", + service: :omni + } -To calculate accurate distance and bearing with SQLite or MongoDB: + ) - obj.distance_to([43.9,-98.6]) # distance from obj to point - obj.bearing_to([43.9,-98.6]) # bearing from obj to point - obj.bearing_from(obj2) # bearing from obj2 to obj +Lookup-specific settings override global settings so, in this example, the timeout for all lookups is 2 seconds, except for Yandex which is 5. -The `bearing_from/to` methods take a single argument which can be: a `[lat,lon]` array, a geocoded object, or a geocodable address (string). The `distance_from/to` methods also take a units argument (`:mi`, `:km`, or `:nm` for nautical miles). +Performance and Optimization +---------------------------- -Model Configuration -------------------- +### Database Indices -You are not stuck with using the `latitude` and `longitude` database column names (with ActiveRecord) or the `coordinates` array (Mongo) for storing coordinates. For example: +In MySQL and Postgres, queries use a bounding box to limit the number of points over which a more precise distance calculation needs to be done. To take advantage of this optimisation, you need to add a composite index on latitude and longitude. In your Rails migration: - geocoded_by :address, :latitude => :lat, :longitude => :lon # ActiveRecord - geocoded_by :address, :coordinates => :coords # MongoDB + add_index :table, [:latitude, :longitude] -The `address` method can return any string you'd use to search Google Maps. For example, any of the following are acceptable: +In MongoDB, by default, the methods `geocoded_by` and `reverse_geocoded_by` create a geospatial index. You can avoid index creation with the `:skip_index option`, for example: -* "714 Green St, Big Town, MO" -* "Eiffel Tower, Paris, FR" -* "Paris, TX, US" + include Geocoder::Model::Mongoid + geocoded_by :address, skip_index: true -If your model has `street`, `city`, `state`, and `country` attributes you might do something like this: +### Avoiding Unnecessary API Requests - geocoded_by :address +Geocoding only needs to be performed under certain conditions. To avoid unnecessary work (and quota usage) you will probably want to geocode an object only when: - def address - [street, city, state, country].compact.join(', ') - end +* an address is present +* the address has been changed since last save (or it has never been saved) -For reverse geocoding, you can also specify an alternate name attribute where the address will be stored. For example: +The exact code will vary depending on the method you use for your geocodable string, but it would be something like this: - reverse_geocoded_by :latitude, :longitude, :address => :location # ActiveRecord - reverse_geocoded_by :coordinates, :address => :loc # MongoDB + after_validation :geocode, if: ->(obj){ obj.address.present? and obj.address_changed? } -You can also configure a specific lookup for your model which will override the globally-configured lookup. For example: +### Caching - geocoded_by :address, :lookup => :yandex +When relying on any external service, it's always a good idea to cache retrieved data. When implemented correctly, it improves your app's response time and stability. It's easy to cache geocoding results with Geocoder -- just configure a cache store: -You can also specify a proc if you want to choose a lookup based on a specific property of an object. For example, you can use specialized lookups for different regions: + Geocoder.configure(cache: Redis.new) - geocoded_by :address, :lookup => lambda{ |obj| obj.geocoder_lookup } +This example uses Redis, but the cache store can be any object that supports these methods: - def geocoder_lookup - if country_code == "RU" - :yandex - elsif country_code == "CN" - :baidu - else - :google - end - end +* `store#[](key)` or `#get` or `#read` - retrieves a value +* `store#[]=(key, value)` or `#set` or `#write` - stores a value +* `store#del(url)` - deletes a value +* `store#keys` - (Optional) Returns array of keys. Used if you wish to expire the entire cache (see below). +Even a plain Ruby hash will work, though it's not a great choice (cleared out when app is restarted, not shared between app instances, etc). -Advanced Querying ------------------ +You can also set a custom prefix to be used for cache keys: -When querying for objects (if you're using ActiveRecord) you can also look within a square rather than a radius (circle) by using the `within_bounding_box` scope: + Geocoder.configure(cache_prefix: "...") - distance = 20 - center_point = [40.71, 100.23] - box = Geocoder::Calculations.bounding_box(center_point, distance) - Venue.within_bounding_box(box) +By default the prefix is `geocoder:` -This can also dramatically improve query performance, especially when used in conjunction with indexes on the latitude/longitude columns. Note, however, that returned results do not include `distance` and `bearing` attributes. Also note that `#near` performs both bounding box and radius queries for speed. +If you need to expire cached content: -You can also specify a minimum radius (if you're using ActiveRecord and not Sqlite) to constrain the -lower bound (ie. think of a donut, or ring) by using the `:min_radius` option: + Geocoder::Lookup.get(Geocoder.config[:lookup]).cache.expire(:all) # expire cached results for current Lookup + Geocoder::Lookup.get(:nominatim).cache.expire("http://...") # expire cached result for a specific URL + Geocoder::Lookup.get(:nominatim).cache.expire(:all) # expire cached results for Google Lookup + # expire all cached results for all Lookups. + # Be aware that this methods spawns a new Lookup object for each Service + Geocoder::Lookup.all_services.each{|service| Geocoder::Lookup.get(service).cache.expire(:all)} - box = Geocoder::Calculations.bounding_box(center_point, distance, :min_radius => 10.5) +Do *not* include the prefix when passing a URL to be expired. Expiring `:all` will only expire keys with the configured prefix -- it will *not* expire every entry in your key/value store. -With ActiveRecord, you can specify alternate latitude and longitude column names for a geocoded model (useful if you store multiple sets of coordinates for each object): +For an example of a cache store with URL expiry, please see examples/autoexpire_cache.rb - Venue.near("Paris", 50, latitude: :secondary_latitude, longitude: :secondary_longitude) +_Before you implement caching in your app please be sure that doing so does not violate the Terms of Service for your geocoding service._ + + +Advanced Model Configuration +---------------------------- +You are not stuck with the `latitude` and `longitude` database column names (with ActiveRecord) or the `coordinates` array (Mongo) for storing coordinates. For example: + + geocoded_by :address, latitude: :lat, longitude: :lon # ActiveRecord + geocoded_by :address, coordinates: :coords # MongoDB + +For reverse geocoding, you can specify the attribute where the address will be stored. For example: + + reverse_geocoded_by :latitude, :longitude, address: :loc # ActiveRecord + reverse_geocoded_by :coordinates, address: :street_address # MongoDB + +To specify geocoding parameters in your model: + + geocoded_by :address, params: {region: "..."} + +Supported parameters: `:lookup`, `:ip_lookup`, `:language`, and `:params`. You can specify an anonymous function if you want to set these on a per-request basis. For example, to use different lookups for objects in different regions: + + geocoded_by :address, lookup: lambda{ |obj| obj.geocoder_lookup } + + def geocoder_lookup + if country_code == "RU" + :yandex + elsif country_code == "CN" + :baidu + else + :nominatim + end + end -Advanced Geocoding ------------------- +### Custom Result Handling -So far we have looked at shortcuts for assigning geocoding results to object attributes. However, if you need to do something fancy, you can skip the auto-assignment by providing a block (takes the object to be geocoded and an array of `Geocoder::Result` objects) in which you handle the parsed geocoding result any way you like, for example: +So far we have seen examples where geocoding results are assigned automatically to predefined object attributes. However, you can skip the auto-assignment by providing a block which handles the parsed geocoding results any way you like, for example: reverse_geocoded_by :latitude, :longitude do |obj,results| if geo = results.first @@ -321,717 +379,130 @@ Every `Geocoder::Result` object, `result`, provides the following data: * `result.country` - string * `result.country_code` - string -If you're familiar with the results returned by the geocoding service you're using you can access even more data (call the `#data` method of any Geocoder::Result object to get the full parsed response), but you'll need to be familiar with the particular `Geocoder::Result` object you're using and the structure of your geocoding service's responses. (See below for links to geocoding service documentation.) - +Most APIs return other data in addition to these globally-supported attributes. To directly access the full response, call the `#data` method of any Geocoder::Result object. See the [API Guide](https://github.com/alexreisner/geocoder/blob/master/README_API_GUIDE.md) for links to documentation for all geocoding services. -Geocoding Service ("Lookup") Configuration ------------------------------------------- - -Geocoder supports a variety of street and IP address geocoding services. The default lookups are `:google` for street addresses and `:freegeoip` for IP addresses. Please see the listing and comparison below for details on specific geocoding services (not all settings are supported by all services). - -To create a Rails initializer with an example configuration: - - rails generate geocoder:config +### Forward and Reverse Geocoding in the Same Model -Some common configuration options are: - - # config/initializers/geocoder.rb - Geocoder.configure( - - # geocoding service (see below for supported options): - :lookup => :yandex, - - # IP address geocoding service (see below for supported options): - :ip_lookup => :maxmind, - - # to use an API key: - :api_key => "...", - - # geocoding service request timeout, in seconds (default 3): - :timeout => 5, - - # set default units to kilometers: - :units => :km, +You can apply both forward and reverse geocoding to the same model (i.e. users can supply an address or coordinates and Geocoder fills in whatever's missing) but you'll need to provide two different address methods: - # caching (see below for details): - :cache => Redis.new, - :cache_prefix => "..." - - ) - -Please see [`lib/geocoder/configuration.rb`](https://github.com/alexreisner/geocoder/blob/master/lib/geocoder/configuration.rb) for a complete list of configuration options. Additionally, some lookups have their own configuration options, some of which are directly supported by Geocoder. For example, to specify a value for Google's `bounds` parameter: - - # with Google: - Geocoder.search("Paris", :bounds => [[32.1,-95.9], [33.9,-94.3]]) - -Please see the [source code for each lookup](https://github.com/alexreisner/geocoder/tree/master/lib/geocoder/lookups) to learn about directly supported parameters. Parameters which are not directly supported can be specified using the `:params` option, by which you can pass arbitrary parameters to any geocoding service. For example, to use Nominatim's `countrycodes` parameter: - - # with Nominatim: - Geocoder.search("Paris", :params => {:countrycodes => "gb,de,fr,es,us"}) - -Or, to search within a particular region with Google: - - Geocoder.search("...", :params => {:region => "..."}) +* one for storing the fetched address (when reverse geocoding) +* one for providing an address to use when fetching coordinates (forward geocoding) -Or, to use parameters in your model: +For example: class Venue # build an address from street, city, and state attributes - geocoded_by :address_from_components, :params => {:region => "..."} + geocoded_by :address_from_components # store the fetched address in the full_address attribute - reverse_geocoded_by :latitude, :longitude, :address => :full_address, :params => {:region => "..."} + reverse_geocoded_by :latitude, :longitude, address: :full_address end +The same goes for latitude/longitude. However, for purposes of querying the database, there can be only one authoritative set of latitude/longitude attributes for use in database queries. This is whichever you specify last. For example, here the attributes *without* the `fetched_` prefix will be authoritative: -### Configure Multiple Services - -You can configure multiple geocoding services at once, like this: - - Geocoder.configure( - - :timeout => 2, - :cache => Redis.new, - - :yandex => { - :api_key => "...", - :timeout => 5 - }, - - :baidu => { - :api_key => "..." - }, - - :maxmind => { - :api_key => "...", - :service => :omni - } - - ) - -The above combines global and service-specific options and could be useful if you specify different geocoding services for different models or under different conditions. Lookup-specific settings override global settings. In the above example, the timeout for all lookups would be 2 seconds, except for Yandex which would be 5. - - -### Street Address Services - -The following is a comparison of the supported geocoding APIs. The "Limitations" listed for each are a very brief and incomplete summary of some special limitations beyond basic data source attribution. Please read the official Terms of Service for a service before using it. - -#### Google (`:google`) - -* **API key**: optional, but quota is higher if key is used (use of key requires HTTPS so be sure to set: `:use_https => true` in `Geocoder.configure`) -* **Key signup**: https://console.developers.google.com/flows/enableapi?apiid=geocoding_backend&keyType=SERVER_SIDE -* **Quota**: 2,500 requests/24 hrs, 5 requests/second -* **Region**: world -* **SSL support**: yes (required if key is used) -* **Languages**: see https://developers.google.com/maps/faq#languagesupport -* **Extra params**: - * `:bounds` - pass SW and NE coordinates as an array of two arrays to bias results towards a viewport - * `:google_place_id` - pass `true` if search query is a Google Place ID -* **Documentation**: https://developers.google.com/maps/documentation/geocoding/intro -* **Terms of Service**: http://code.google.com/apis/maps/terms.html#section_10_12 -* **Limitations**: "You must not use or display the Content without a corresponding Google map, unless you are explicitly permitted to do so in the Maps APIs Documentation, or through written permission from Google." "You must not pre-fetch, cache, or store any Content, except that you may store: (i) limited amounts of Content for the purpose of improving the performance of your Maps API Implementation..." - -#### Google Maps API for Work (`:google_premier`) - -Similar to `:google`, with the following differences: - -* **API key**: required, plus client and channel (set `Geocoder.configure(:lookup => :google_premier, :api_key => [key, client, channel])`) -* **Key signup**: https://developers.google.com/maps/documentation/business/ -* **Quota**: 100,000 requests/24 hrs, 10 requests/second - -#### Google Places Details (`:google_places_details`) - -The [Google Places Details API](https://developers.google.com/places/documentation/details) is not, strictly speaking, a geocoding service. It accepts a Google `place_id` and returns address information, ratings and reviews. A `place_id` can be obtained from the Google Places Search lookup (`:google_places_search`) and should be passed to Geocoder as the first search argument: `Geocoder.search("ChIJhRwB-yFawokR5Phil-QQ3zM", lookup: :google_places_details)`. - -* **API key**: required -* **Key signup**: https://code.google.com/apis/console/ -* **Quota**: 1,000 request/day, 100,000 after credit card authentication -* **Region**: world -* **SSL support**: yes -* **Languages**: ar, eu, bg, bn, ca, cs, da, de, el, en, en-AU, en-GB, es, eu, fa, fi, fil, fr, gl, gu, hi, hr, hu, id, it, iw, ja, kn, ko, lt, lv, ml, mr, nl, no, pl, pt, pt-BR, pt-PT, ro, ru, sk, sl, sr, sv, tl, ta, te, th, tr, uk, vi, zh-CN, zh-TW (see http://spreadsheets.google.com/pub?key=p9pdwsai2hDMsLkXsoM05KQ&gid=1) -* **Documentation**: https://developers.google.com/places/documentation/details -* **Terms of Service**: https://developers.google.com/places/policies -* **Limitations**: "If your application displays Places API data on a page or view that does not also display a Google Map, you must show a "Powered by Google" logo with that data." - -#### Google Places Search (`:google_places_search`) - -The [Google Places Search API](https://developers.google.com/places/web-service/search) is the geocoding service of Google Places API. It returns very limited location data, but it also returns a `place_id` which can be used with Google Place Details to get more detailed information. For a comparison between this and the regular Google Geocoding API, see https://maps-apis.googleblog.com/2016/11/address-geocoding-in-google-maps-apis.html - -* Same specifications as Google Places Details (see above). - -#### Bing (`:bing`) - -* **API key**: required (set `Geocoder.configure(:lookup => :bing, :api_key => key)`) -* **Key signup**: https://www.microsoft.com/maps/create-a-bing-maps-key.aspx -* **Quota**: 50,0000 requests/day (Windows app), 125,000 requests/year (non-Windows app) -* **Region**: world -* **SSL support**: no -* **Languages**: ? -* **Documentation**: http://msdn.microsoft.com/en-us/library/ff701715.aspx -* **Terms of Service**: http://www.microsoft.com/maps/product/terms.html -* **Limitations**: No country codes or state names. Must be used on "public-facing, non-password protected web sites," "in conjunction with Bing Maps or an application that integrates Bing Maps." - -#### Nominatim (`:nominatim`) - -* **API key**: none -* **Quota**: 1 request/second -* **Region**: world -* **SSL support**: no -* **Languages**: ? -* **Documentation**: http://wiki.openstreetmap.org/wiki/Nominatim -* **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) - -#### PickPoint (`:pickpoint`) - -* **API key**: required -* **Key signup**: [https://pickpoint.io](https://pickpoint.io) -* **Quota**: 2500 requests / day for free non-commercial usage, commercial plans are [available](https://pickpoint.io/#pricing). No rate limit. -* **Region**: world -* **SSL support**: required -* **Languages**: worldwide -* **Documentation**: [https://pickpoint.io/api-reference](https://pickpoint.io/api-reference) -* **Limitations**: [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://www.openstreetmap.org/copyright) - - -#### LocationIQ (`:location_iq`) - -* **API key**: required -* **Quota**: 60 requests/minute (2 req/sec, 10k req/day), then [ability to purchase more](http://locationiq.org/#pricing) -* **Region**: world -* **SSL support**: yes -* **Languages**: ? -* **Documentation**: https://locationiq.org/#docs -* **Terms of Service**: https://unwiredlabs.com/tos -* **Limitations**: [Data licensed under Open Database License (ODbL) (you must provide attribution).](https://www.openstreetmap.org/copyright) - -#### OpenCageData (`:opencagedata`) - -* **API key**: required -* **Key signup**: http://geocoder.opencagedata.com -* **Quota**: 2500 requests / day, then [ability to purchase more](https://geocoder.opencagedata.com/pricing) -* **Region**: world -* **SSL support**: yes -* **Languages**: worldwide -* **Documentation**: http://geocoder.opencagedata.com/api.html -* **Limitations**: [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://www.openstreetmap.org/copyright) - -#### Yandex (`:yandex`) - -* **API key**: optional, but without it lookup is territorially limited -* **Quota**: 25000 requests / day -* **Region**: world with API key. Otherwise restricted to Russia, Ukraine, Belarus, Kazakhstan, Georgia, Abkhazia, South Ossetia, Armenia, Azerbaijan, Moldova, Turkmenistan, Tajikistan, Uzbekistan, Kyrgyzstan and Turkey -* **SSL support**: HTTPS only -* **Languages**: Russian, Belarusian, Ukrainian, English, Turkish (only for maps of Turkey) -* **Documentation**: http://api.yandex.com.tr/maps/doc/intro/concepts/intro.xml -* **Terms of Service**: http://api.yandex.com.tr/maps/doc/intro/concepts/intro.xml#rules -* **Limitations**: ? - -#### Geocoder.ca (`:geocoder_ca`) - -* **API key**: none -* **Quota**: ? -* **Region**: US and Canada -* **SSL support**: no -* **Languages**: English -* **Documentation**: ? -* **Terms of Service**: http://geocoder.ca/?terms=1 -* **Limitations**: "Under no circumstances can our data be re-distributed or re-sold by anyone to other parties without our written permission." - -#### Mapbox (`:mapbox`) - -* **API key**: required -* **Dataset**: Uses `mapbox.places` dataset by default. Specify the `mapbox.places-permanent` dataset by setting: `Geocoder.configure(:mapbox => {:dataset => "mapbox.places-permanent"})` -* **Key signup**: https://www.mapbox.com/pricing/ -* **Quota**: depends on plan -* **Region**: complete coverage of US and Canada, partial coverage elsewhere (see for details: https://www.mapbox.com/developers/api/geocoding/#coverage) -* **SSL support**: yes -* **Languages**: English -* **Extra params** (see Mapbox docs for more): - * `:country` - restrict results to a specific country, e.g., `us` or `ca` - * `:types` - restrict results to categories such as `address`, - `neighborhood`, `postcode` - * `:proximity` - bias results toward a `lng,lat`, e.g., - `params: { proximity: "-84.0,42.5" }` -* **Documentation**: https://www.mapbox.com/developers/api/geocoding/ -* **Terms of Service**: https://www.mapbox.com/tos/ -* **Limitations**: For `mapbox.places` dataset, must be displayed on a Mapbox map; Cache results for up to 30 days. For `mapbox.places-permanent` dataset, depends on plan. -* **Notes**: Currently in public beta. - -#### Mapquest (`:mapquest`) - -* **API key**: required -* **Key signup**: https://developer.mapquest.com/plans -* **Quota**: ? -* **HTTP Headers**: when using the licensed API you can specify a referer like so: - `Geocoder.configure(:http_headers => { "Referer" => "http://foo.com" })` -* **Region**: world -* **SSL support**: no -* **Languages**: English -* **Documentation**: http://www.mapquestapi.com/geocoding/ -* **Terms of Service**: http://info.mapquest.com/terms-of-use/ -* **Limitations**: ? -* **Notes**: You can use the open (non-licensed) API by setting: `Geocoder.configure(:mapquest => {:open => true})` (defaults to licensed version) - -#### Ovi/Nokia (`:ovi`) - -* **API key**: not required, but performance restricted without it -* **Quota**: ? -* **Region**: world -* **SSL support**: no -* **Languages**: English -* **Documentation**: http://api.maps.ovi.com/devguide/overview.html -* **Terms of Service**: http://www.developer.nokia.com/Develop/Maps/TC.html -* **Limitations**: ? - -#### Here/Nokia (`:here`) - -* **API key**: required (set `Geocoder.configure(:api_key => [app_id, app_code])`) -* **Quota**: Depending on the API key -* **Region**: world -* **SSL support**: yes -* **Languages**: The preferred language of address elements in the result. Language code must be provided according to RFC 4647 standard. -* **Documentation**: http://developer.here.com/rest-apis/documentation/geocoder -* **Terms of Service**: http://developer.here.com/faqs#l&t -* **Limitations**: ? - -#### ESRI (`:esri`) - -* **API key**: optional (set `Geocoder.configure(:esri => {:api_key => ["client_id", "client_secret"]})`) -* **Quota**: Required for some scenarios (see Terms of Service) -* **Region**: world -* **SSL support**: yes -* **Languages**: English -* **Documentation**: https://developers.arcgis.com/rest/geocode/api-reference/overview-world-geocoding-service.htm -* **Terms of Service**: http://www.esri.com/legal/software-license -* **Limitations**: Requires API key if results will be stored. Using API key will also remove rate limit. -* **Notes**: You can specify which projection you want to use by setting, for example: `Geocoder.configure(:esri => {:outSR => 102100})`. If you will store results, set the flag and provide API key: `Geocoder.configure(:esri => {:api_key => ["client_id", "client_secret"], :for_storage => true})`. If you want to, you can also supply an ESRI token directly: `Geocoder.configure(:esri => {:token => Geocoder::EsriToken.new('TOKEN', Time.now + 1.day})` - -#### Mapzen (`:mapzen`) - -* **API key**: required -* **Quota**: 25,000 free requests/month and [ability to purchase more](https://mapzen.com/pricing/) -* **Region**: world -* **SSL support**: yes -* **Languages**: en; see https://mapzen.com/documentation/search/language-codes/ -* **Documentation**: https://mapzen.com/documentation/search/search/ -* **Terms of Service**: http://mapzen.com/terms -* **Limitations**: [You must provide attribution](https://mapzen.com/rights/) -* **Notes**: Mapzen is the primary author of Pelias and offers Pelias-as-a-service in free and paid versions https://mapzen.com/pelias. - -#### Pelias (`:pelias`) - -* **API key**: configurable (self-hosted service) -* **Quota**: none (self-hosted service) -* **Region**: world -* **SSL support**: yes -* **Languages**: en; see https://mapzen.com/documentation/search/language-codes/ -* **Documentation**: http://pelias.io/ -* **Terms of Service**: http://pelias.io/data_licenses.html -* **Limitations**: See terms -* **Notes**: Configure your self-hosted pelias with the `endpoint` option: `Geocoder.configure(:lookup => :pelias, :api_key => 'your_api_key', :pelias => {:endpoint => 'self.hosted/pelias'})`. Defaults to `localhost`. - -#### Data Science Toolkit (`:dstk`) - -Data Science Toolkit provides an API whose response format is like Google's but which can be set up as a privately hosted service. - -* **API key**: none -* **Quota**: No quota if you are self-hosting the service. -* **Region**: world -* **SSL support**: ? -* **Languages**: en -* **Documentation**: http://www.datasciencetoolkit.org/developerdocs -* **Terms of Service**: http://www.datasciencetoolkit.org/developerdocs#googlestylegeocoder -* **Limitations**: No reverse geocoding. -* **Notes**: If you are hosting your own DSTK server you will need to configure the host name, eg: `Geocoder.configure(:lookup => :dstk, :dstk => {:host => "localhost:4567"})`. - -#### Baidu (`:baidu`) - -* **API key**: required -* **Quota**: No quota limits for geocoding -* **Region**: China -* **SSL support**: no -* **Languages**: Chinese (Simplified) -* **Documentation**: http://developer.baidu.com/map/webservice-geocoding.htm -* **Terms of Service**: http://developer.baidu.com/map/law.htm -* **Limitations**: Only good for non-commercial use. For commercial usage please check http://developer.baidu.com/map/question.htm#qa0013 -* **Notes**: To use Baidu set `Geocoder.configure(:lookup => :baidu, :api_key => "your_api_key")`. - -#### Geocodio (`:geocodio`) - -* **API key**: required -* **Quota**: 2,500 free requests/day then purchase $0.0005 for each, also has volume pricing and plans. -* **Region**: US -* **SSL support**: yes -* **Languages**: en -* **Documentation**: http://geocod.io/docs -* **Terms of Service**: http://geocod.io/terms-of-use -* **Limitations**: No restrictions on use - -#### SmartyStreets (`:smarty_streets`) - -* **API key**: requires auth_id and auth_token (set `Geocoder.configure(:api_key => [id, token])`) -* **Quota**: 250/month then purchase at sliding scale. -* **Region**: US -* **SSL support**: yes (required) -* **Languages**: en -* **Documentation**: http://smartystreets.com/kb/liveaddress-api/rest-endpoint -* **Terms of Service**: http://smartystreets.com/legal/terms-of-service -* **Limitations**: No reverse geocoding. - - -#### OKF Geocoder (`:okf`) - -* **API key**: none -* **Quota**: none -* **Region**: FI -* **SSL support**: no -* **Languages**: fi -* **Documentation**: http://books.okf.fi/geocoder/_full/ -* **Terms of Service**: http://www.itella.fi/liitteet/palvelutjatuotteet/yhteystietopalvelut/Postinumeropalvelut-Palvelukuvausjakayttoehdot.pdf -* **Limitations**: ? - -#### Geoportail.lu (`:geoportail_lu`) - -* **API key**: none -* **Quota**: none -* **Region**: LU -* **SSL support**: yes -* **Languages**: en -* **Documentation**: http://wiki.geoportail.lu/doku.php?id=en:api -* **Terms of Service**: http://wiki.geoportail.lu/doku.php?id=en:mcg_1 -* **Limitations**: ? - -#### PostcodeAnywhere Uk (`:postcode_anywhere_uk`) - -This uses the PostcodeAnywhere UK Geocode service, this will geocode any string from UK postcode, placename, point of interest or location. - -* **API key**: required -* **Quota**: Dependant on service plan? -* **Region**: UK -* **SSL support**: yes -* **Languages**: English -* **Documentation**: [http://www.postcodeanywhere.co.uk/Support/WebService/Geocoding/UK/Geocode/2/](http://www.postcodeanywhere.co.uk/Support/WebService/Geocoding/UK/Geocode/2/) -* **Terms of Service**: ? -* **Limitations**: ? -* **Notes**: To use PostcodeAnywhere you must include an API key: `Geocoder.configure(:lookup => :postcode_anywhere_uk, :api_key => 'your_api_key')`. - -#### LatLon.io (`:latlon`) - -* **API key**: required -* **Quota**: Depends on the user's plan (free and paid plans available) -* **Region**: US -* **SSL support**: yes -* **Languages**: en -* **Documentation**: https://latlon.io/documentation -* **Terms of Service**: ? -* **Limitations**: No restrictions on use - -#### Base Adresse Nationale FR (`:ban_data_gouv_fr`) - -* **API key**: none -* **Quota**: none -* **Region**: FR -* **SSL support**: yes -* **Languages**: en / fr -* **Documentation**: https://adresse.data.gouv.fr/api/ (in french) -* **Terms of Service**: https://adresse.data.gouv.fr/faq/ (in french) -* **Limitations**: [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://openstreetmap.fr/ban) - -#### AMap (`:amap`) - -- **API key**: required -- **Quota**: 2000/day and 2000/minute for personal developer, 4000000/day and 60000/minute for enterprise developer, for geocoding requests -- **Region**: China -- **SSL support**: yes -- **Languages**: Chinese (Simplified) -- **Documentation**: http://lbs.amap.com/api/webservice/guide/api/georegeo -- **Terms of Service**: http://lbs.amap.com/home/terms/ -- **Limitations**: Only good for non-commercial use. For commercial usage please check http://lbs.amap.com/home/terms/ -- **Notes**: To use AMap set `Geocoder.configure(:lookup => :amap, :api_key => "your_api_key")`. - -### IP Address Services - -#### FreeGeoIP (`:freegeoip`) - -* **API key**: none -* **Quota**: 15,000 requests per hour. After reaching the hourly quota, all of your requests will result in HTTP 403 (Forbidden) until it clears up on the next roll over. -* **Region**: world -* **SSL support**: no -* **Languages**: English -* **Documentation**: http://github.com/fiorix/freegeoip/blob/master/README.md -* **Terms of Service**: ? -* **Limitations**: ? -* **Notes**: If you are [running your own local instance of the FreeGeoIP service](https://github.com/fiorix/freegeoip) you can configure the host like this: `Geocoder.configure(freegeoip: {host: "..."})`. - -#### Pointpin (`:pointpin`) - -* **API key**: required -* **Quota**: 50,000/mo for €9 through 1m/mo for €49 -* **Region**: world -* **SSL support**: yes -* **Languages**: English -* **Documentation**: https://pointp.in/docs/get-started -* **Terms of Service**: https://pointp.in/terms -* **Limitations**: ? -* **Notes**: To use Pointpin set `Geocoder.configure(:ip_lookup => :pointpin, :api_key => "your_pointpin_api_key")`. - -#### Telize (`:telize`) - -* **API key**: required -* **Quota**: 1,000/day for $7/mo through 100,000/day for $100/mo -* **Region**: world -* **SSL support**: yes -* **Languages**: English -* **Documentation**: https://market.mashape.com/fcambus/telize -* **Terms of Service**: ? -* **Limitations**: ? -* **Notes**: To use Telize set `Geocoder.configure(:ip_lookup => :telize, :api_key => "your_api_key")`. Or configure your self-hosted telize with the `host` option: `Geocoder.configure(:ip_lookup => :telize, :telize => {:host => "localhost"})`. - - -#### MaxMind Legacy Web Services (`:maxmind`) - -* **API key**: required -* **Quota**: Request Packs can be purchased -* **Region**: world -* **SSL support**: yes -* **Languages**: English -* **Documentation**: http://dev.maxmind.com/geoip/legacy/web-services/ -* **Terms of Service**: ? -* **Limitations**: ? -* **Notes**: You must specify which MaxMind service you are using in your configuration. For example: `Geocoder.configure(:maxmind => {:service => :omni})`. - -#### Baidu IP (`:baidu_ip`) - -* **API key**: required -* **Quota**: No quota limits for geocoding -* **Region**: China -* **SSL support**: no -* **Languages**: Chinese (Simplified) -* **Documentation**: http://developer.baidu.com/map/webservice-geocoding.htm -* **Terms of Service**: http://developer.baidu.com/map/law.htm -* **Limitations**: Only good for non-commercial use. For commercial usage please check http://developer.baidu.com/map/question.htm#qa0013 -* **Notes**: To use Baidu set `Geocoder.configure(:lookup => :baidu_ip, :api_key => "your_api_key")`. - -#### MaxMind GeoIP2 Precision Web Services (`:maxmind_geoip2`) - -* **API key**: required -* **Quota**: Request Packs can be purchased -* **Region**: world -* **SSL support**: yes -* **Languages**: English -* **Documentation**: http://dev.maxmind.com/geoip/geoip2/web-services/ -* **Terms of Service**: ? -* **Limitations**: ? -* **Notes**: You must specify which MaxMind service you are using in your configuration, and also basic authentication. For example: `Geocoder.configure(:maxmind_geoip2 => {:service => :country, :basic_auth => {:user => '', :password => ''}})`. - -#### IPInfo.io (`:ipinfo_io`) - -* **API key**: optional - see http://ipinfo.io/pricing -* **Quota**: 1,000/day - more with api key -* **Region**: world -* **SSL support**: no (not without access key - see http://ipinfo.io/pricing) -* **Languages**: English -* **Documentation**: http://ipinfo.io/developers -* **Terms of Service**: http://ipinfo.io/developers - -#### IP-API.com (`:ipapi_com`) - -* **API key**: optional - see http://ip-api.com/docs/#usage_limits -* **Quota**: 150/minute - unlimited with api key -* **Region**: world -* **SSL support**: no (not without access key - see https://signup.ip-api.com/) -* **Languages**: English -* **Documentation**: http://ip-api.com/docs/ -* **Terms of Service**: https://signup.ip-api.com/terms - -#### DB-IP.com (`:db_ip_com`) - -* **API key**: required -* **Quota**: 2,500/day (with free API Key, 50,000/day and up for paid API keys) -* **Region**: world -* **SSL support**: yes (with paid API keys - see https://db-ip.com/api/) -* **Languages**: English (English with free API key, multiple languages with paid API keys) -* **Documentation**: https://db-ip.com/api/doc.php -* **Terms of Service**: https://db-ip.com/tos.php - -### IP Address Local Database Services - -#### MaxMind Local (`:maxmind_local`) - EXPERIMENTAL - -This lookup provides methods for geocoding IP addresses without making a call to a remote API (improves speed and availability). It works, but support is new and should not be considered production-ready. Please [report any bugs](https://github.com/alexreisner/geocoder/issues) you encounter. - -* **API key**: none (requires the GeoLite City database which can be downloaded from [MaxMind](http://dev.maxmind.com/geoip/legacy/geolite/)) -* **Quota**: none -* **Region**: world -* **SSL support**: N/A -* **Languages**: English -* **Documentation**: http://www.maxmind.com/en/city -* **Terms of Service**: ? -* **Limitations**: ? -* **Notes**: There are two supported formats for MaxMind local data: binary file, and CSV file imported into an SQL database. **You must download a database from MaxMind and set either the `:file` or `:package` configuration option for local lookups to work.** - -**To use a binary file** you must add the *geoip* (or *jgeoip* for JRuby) gem to your Gemfile or have it installed in your system, and specify the path of the MaxMind database in your configuration. For example: - - Geocoder.configure(ip_lookup: :maxmind_local, maxmind_local: {file: File.join('folder', 'GeoLiteCity.dat')}) - -**To use a CSV file** you must import it into an SQL database. The GeoLite *City* and *Country* packages are supported. Configure like so: - - Geocoder.configure(ip_lookup: :maxmind_local, maxmind_local: {package: :city}) - -You can generate ActiveRecord migrations and download and import data via provided rake tasks: - - # generate migration to create tables - rails generate geocoder:maxmind:geolite_city - - # download, unpack, and import data - rake geocoder:maxmind:geolite:load PACKAGE=city - -You can replace `city` with `country` in any of the above tasks, generators, and configurations. - -#### GeoLite2 (`:geoip2`) - -This lookup provides methods for geocoding IP addresses without making a call to a remote API (improves speed and availability). It works, but support is new and should not be considered production-ready. Please [report any bugs](https://github.com/alexreisner/geocoder/issues) you encounter. - -* **API key**: none (requires a GeoIP2 or free GeoLite2 City or Country binary database which can be downloaded from [MaxMind](http://dev.maxmind.com/geoip/geoip2/)) -* **Quota**: none -* **Region**: world -* **SSL support**: N/A -* **Languages**: English -* **Documentation**: http://www.maxmind.com/en/city -* **Terms of Service**: ? -* **Limitations**: ? -* **Notes**: **You must download a binary database file from MaxMind and set the `:file` configuration option.** The CSV format databases are not yet supported since they are still in alpha stage. Set the path to the database file in your configuration: - - Geocoder.configure( - ip_lookup: :geoip2, - geoip2: { - file: File.join('folder', 'GeoLite2-City.mmdb') - } - ) - -You must add either the *[hive_geoip2](https://rubygems.org/gems/hive_geoip2)* gem (native extension that relies on libmaxminddb) or the *[maxminddb](http://rubygems.org/gems/maxminddb)* gem (pure Ruby implementation) to your Gemfile or have it installed in your system. The pure Ruby gem (maxminddb) will be used by default. To use `hive_geoip2`: - - Geocoder.configure( - ip_lookup: :geoip2, - geoip2: { - lib: 'hive_geoip2', - file: File.join('folder', 'GeoLite2-City.mmdb') - } - ) - -Caching -------- - -When relying on any external service, it's always a good idea to cache retrieved data. When implemented correctly, it improves your app's response time and stability. It's easy to cache geocoding results with Geocoder -- just configure a cache store: - - Geocoder.configure(:cache => Redis.new) - -This example uses Redis, but the cache store can be any object that supports these methods: - -* `store#[](key)` or `#get` or `#read` - retrieves a value -* `store#[]=(key, value)` or `#set` or `#write` - stores a value -* `store#del(url)` - deletes a value -* `store#keys` - (Optional) Returns array of keys. Used if you wish to expire the entire cache (see below). - -Even a plain Ruby hash will work, though it's not a great choice (cleared out when app is restarted, not shared between app instances, etc). + class Venue + geocoded_by :address, + latitude: :fetched_latitude, + longitude: :fetched_longitude + reverse_geocoded_by :latitude, :longitude + end -You can also set a custom prefix to be used for cache keys: - Geocoder.configure(:cache_prefix => "...") +Advanced Database Queries +------------------------- -By default the prefix is `geocoder:` +*The following apply to ActiveRecord only. For MongoDB, please use the built-in geospatial features.* -If you need to expire cached content: +The default `near` search looks for objects within a circle. To search within a doughnut or ring use the `:min_radius` option: - Geocoder::Lookup.get(Geocoder.config[:lookup]).cache.expire(:all) # expire cached results for current Lookup - Geocoder::Lookup.get(:google).cache.expire("http://...") # expire cached result for a specific URL - Geocoder::Lookup.get(:google).cache.expire(:all) # expire cached results for Google Lookup - # expire all cached results for all Lookups. - # Be aware that this methods spawns a new Lookup object for each Service - Geocoder::Lookup.all_services.each{|service| Geocoder::Lookup.get(service).cache.expire(:all)} + Venue.near("Austin, TX", 200, min_radius: 40) -Do *not* include the prefix when passing a URL to be expired. Expiring `:all` will only expire keys with the configured prefix -- it will *not* expire every entry in your key/value store. +To search within a rectangle (note that results will *not* include `distance` and `bearing` attributes): -For an example of a cache store with URL expiry, please see examples/autoexpire_cache.rb + sw_corner = [40.71, 100.23] + ne_corner = [36.12, 88.65] + Venue.within_bounding_box(sw_corner, ne_corner) -_Before you implement caching in your app please be sure that doing so does not violate the Terms of Service for your geocoding service._ +To search for objects near a certain point where each object has a different distance requirement (which is defined in the database), you can pass a column name for the radius: + Venue.near([40.71, 99.23], :effective_radius) -Forward and Reverse Geocoding in the Same Model ------------------------------------------------ +If you store multiple sets of coordinates for each object, you can specify latitude and longitude columns to use for a search: -If you apply both forward and reverse geocoding functionality to the same model (i.e. users can supply an address or coordinates and you want to fill in whatever's missing), you will provide two address methods: + Venue.near("Paris", 50, latitude: :secondary_latitude, longitude: :secondary_longitude) -* one for storing the fetched address (reverse geocoding) -* one for providing an address to use when fetching coordinates (forward geocoding) +### Distance and Bearing -For example: +When you run a geospatial query, the returned objects have two attributes added: - class Venue +* `obj.distance` - number of miles from the search point to this object +* `obj.bearing` - direction from the search point to this object - # build an address from street, city, and state attributes - geocoded_by :address_from_components +Results are automatically sorted by distance from the search point, closest to farthest. Bearing is given as a number of degrees clockwise from due north, for example: - # store the fetched address in the full_address attribute - reverse_geocoded_by :latitude, :longitude, :address => :full_address - end +* `0` - due north +* `180` - due south +* `90` - due east +* `270` - due west +* `230.1` - southwest +* `359.9` - almost due north -However, there can be only one set of latitude/longitude attributes, and whichever you specify last will be used. For example: +You can convert these to compass point names via provided method: - class Venue + Geocoder::Calculations.compass_point(355) # => "N" + Geocoder::Calculations.compass_point(45) # => "NE" + Geocoder::Calculations.compass_point(208) # => "SW" - geocoded_by :address, - :latitude => :fetched_latitude, # this will be overridden by the below - :longitude => :fetched_longitude # same here +_Note: when running queries on SQLite, `distance` and `bearing` are provided for consistency only. They are not very accurate._ - reverse_geocoded_by :latitude, :longitude - end +For more advanced geospatial querying, please see the [rgeo gem](https://github.com/rgeo/rgeo). -We don't want ambiguity when doing distance calculations -- we need a single, authoritative source for coordinates! -Once both forward and reverse geocoding has been applied, it is possible to call them sequentially. +Geospatial Calculations +----------------------- -For example: +The `Geocoder::Calculations` module contains some useful methods: - class Venue + # find the distance between two arbitrary points + Geocoder::Calculations.distance_between([47.858205,2.294359], [40.748433,-73.985655]) + => 3619.77359999382 # in configured units (default miles) - after_validation :geocode, :reverse_geocode + # find the geographic center (aka center of gravity) of objects or points + Geocoder::Calculations.geographic_center([city1, city2, [40.22,-73.99], city4]) + => [35.14968, -90.048929] - end +See [the code](https://github.com/alexreisner/geocoder/blob/master/lib/geocoder/calculations.rb) for more! -For certain geolocation services such as Google's geolocation API, this may cause issues during subsequent updates to database records if the longitude and latitude coordinates cannot be associated with a known location address (on a large body of water for example). On subsequent callbacks the following call: - after_validation :geocode +Batch Geocoding +--------------- -will alter the longitude and latitude attributes based on the location field, which would be the closest known location to the original coordinates. In this case it is better to add conditions to each call, as not to override coordinates that do not have known location addresses associated with them. +If you have just added geocoding to an existing application with a lot of objects, you can use this Rake task to geocode them all: -For example: + rake geocode:all CLASS=YourModel - class Venue +If you need reverse geocoding instead, call the task with REVERSE=true: - after_validation :reverse_geocode, :if => :has_coordinates - after_validation :geocode, :if => :has_location, :unless => :has_coordinates + rake geocode:all CLASS=YourModel REVERSE=true - end +In either case, it won't try to geocode objects that are already geocoded. The task will print warnings if you exceed the rate limit for your geocoding service. Some services enforce a per-second limit in addition to a per-day limit. To avoid exceeding the per-second limit, you can add a `SLEEP` option to pause between requests for a given amount of time. You can also load objects in batches to save memory, for example: -Use Outside of Rails --------------------- + rake geocode:all CLASS=YourModel SLEEP=0.25 BATCH=100 -You can use Geocoder outside of Rails by calling the `Geocoder.search` method: +To avoid exceeding per-day limits you can add a `LIMIT` option. However, this will ignore the `BATCH` value, if provided. - results = Geocoder.search("McCarren Park, Brooklyn, NY") + rake geocode:all CLASS=YourModel LIMIT=1000 -This returns an array of `Geocoder::Result` objects with all data provided by the geocoding service. +Testing +------- -Testing Apps that Use Geocoder ------------------------------- +When writing tests for an app that uses Geocoder it may be useful to avoid network calls and have Geocoder return consistent, configurable results. To do this, configure the `:test` lookup and/or `:ip_lookup` -When writing tests for an app that uses Geocoder it may be useful to avoid network calls and have Geocoder return consistent, configurable results. To do this, configure and use the `:test` lookup. For example: + Geocoder.configure(lookup: :test, ip_lookup: :test) - Geocoder.configure(:lookup => :test) +Add stubs to define the results that will be returned: Geocoder::Lookup::Test.add_stub( "New York, NY", [ @@ -1046,9 +517,7 @@ When writing tests for an app that uses Geocoder it may be useful to avoid netwo ] ) -Now, any time Geocoder looks up "New York, NY" its results array will contain one result with the above attributes. Note each lookup requires an exact match to the text you provide as the first argument. The above example would, therefore, not match a request for "New York, NY, USA" and a second stub would need to be created to match that particular request. You can also set a default stub, to be returned when no other stub is found for a given query: - - Geocoder.configure(:lookup => :test) +With the above stub defined, any query for "New York, NY" will return the results array that follows. You can also set a default stub, to be returned when no other stub matches a given query: Geocoder::Lookup::Test.set_default_stub( [ @@ -1065,8 +534,33 @@ Now, any time Geocoder looks up "New York, NY" its results array will contain on Notes: -- Keys must be strings not symbols when calling `add_stub` or `set_default_stub`. For example `'latitude' =>` not `:latitude =>`. +- Keys must be strings (not symbols) when calling `add_stub` or `set_default_stub`. For example `'country' =>` not `:country =>`. - To clear stubs (e.g. prior to another spec), use `Geocoder::Lookup::Test.reset`. This will clear all stubs _including the default stub_. +- The stubbed result objects returned by the Test lookup do not support all the methods real result objects do. If you need to test interaction with real results it may be better to use an external stubbing tool and something like WebMock or VCR to prevent network calls. + + +Error Handling +-------------- + +By default Geocoder will rescue any exceptions raised by calls to a geocoding service and return an empty array. You can override this on a per-exception basis, and also have Geocoder raise its own exceptions for certain events (eg: API quota exceeded) by using the `:always_raise` option: + + Geocoder.configure(always_raise: [SocketError, Timeout::Error]) + +You can also do this to raise all exceptions: + + Geocoder.configure(always_raise: :all) + +The raise-able exceptions are: + + SocketError + Timeout::Error + Geocoder::OverQueryLimitError + Geocoder::RequestDenied + Geocoder::InvalidRequest + Geocoder::InvalidApiKey + Geocoder::ServiceUnavailable + +Note that only a few of the above exceptions are raised by any given lookup, so there's no guarantee if you configure Geocoder to raise `ServiceUnavailable` that it will actually be raised under those conditions (because most APIs don't return 503 when they should; you may get a `Timeout::Error` instead). Please see the source code for your particular lookup for details. Command Line Interface @@ -1082,63 +576,18 @@ When you install the Geocoder gem it adds a `geocode` command to your shell. You State/province: Louisiana Postal code: 70112 Country: United States - Google map: http://maps.google.com/maps?q=29.952211,-90.080563 + Map: http://maps.google.com/maps?q=29.952211,-90.080563 There are also a number of options for setting the geocoding API, key, and language, viewing the raw JSON response, and more. Please run `geocode -h` for details. -Numeric Data Types and Precision --------------------------------- - -Geocoder works with any numeric data type (e.g. float, double, decimal) on which trig (and other mathematical) functions can be performed. - -A summary of the relationship between geographic precision and the number of decimal places in latitude and longitude degree values is available on [Wikipedia](http://en.wikipedia.org/wiki/Decimal_degrees#Accuracy). As an example: at the equator, latitude/longitude values with 4 decimal places give about 11 metres precision, whereas 5 decimal places gives roughly 1 metre precision. - -Notes on MongoDB ----------------- - -### The Near Method - -Mongo document classes (Mongoid and MongoMapper) have a built-in `near` scope, but since it only works two-dimensions Geocoder overrides it with its own spherical `near` method in geocoded classes. - -### Latitude/Longitude Order - -Coordinates are generally printed and spoken as latitude, then longitude ([lat,lon]). Geocoder respects this convention and always expects method arguments to be given in [lat,lon] order. However, MongoDB requires that coordinates be stored in [lon,lat] order as per the GeoJSON spec (http://geojson.org/geojson-spec.html#positions), so internally they are stored "backwards." However, this does not affect order of arguments to methods when using Mongoid or MongoMapper. - -To access an object's coordinates in the conventional order, use the `to_coordinates` instance method provided by Geocoder. For example: - - obj.to_coordinates # => [37.7941013, -122.3951096] # [lat, lon] - -Calling `obj.coordinates` directly returns the internal representation of the coordinates which, in the case of MongoDB, is probably the reverse of what you want: - - obj.coordinates # => [-122.3951096, 37.7941013] # [lon, lat] - -For consistency with the rest of Geocoder, always use the `to_coordinates` method instead. - -Notes on Non-Rails Frameworks ------------------------------ - -If you are using Geocoder with ActiveRecord and a framework other than Rails (like Sinatra or Padrino), you will need to add this in your model before calling Geocoder methods: - - extend Geocoder::Model::ActiveRecord - -Optimisation of Distance Queries --------------------------------- -In MySQL and Postgres, the finding of objects near a given point is sped up by using a bounding box to limit the number of points over which a full distance calculation needs to be done. +Technical Discussions +--------------------- -To take advantage of this optimisation, you need to add a composite index on latitude and longitude. In your Rails migration: - - add_index :table, [:latitude, :longitude] - - -Distance Queries in SQLite --------------------------- +### Distance Queries in SQLite SQLite's lack of trigonometric functions requires an alternate implementation of the `near` scope. When using SQLite, Geocoder will automatically use a less accurate algorithm for finding objects near a given point. Results of this algorithm should not be trusted too much as it will return objects that are outside the given radius, along with inaccurate distance and bearing calculations. - -### Discussion - There are few options for finding objects near a given point in SQLite without installing extensions: 1. Use a square instead of a circle for finding nearby points. For example, if you want to find points near 40.71, 100.23, search for objects with latitude between 39.71 and 41.71 and longitude between 99.23 and 101.23. One degree of latitude or longitude is at most 69 miles so divide your radius (in miles) by 69.0 to get the amount to add and subtract from your center coordinates to get the upper and lower bounds. The results will not be very accurate (you'll get points outside the desired radius), but you will get all the points within the required radius. @@ -1149,37 +598,11 @@ There are few options for finding objects near a given point in SQLite without i Because Geocoder needs to provide this functionality as a scope, we must go with option #1, but feel free to implement #2 or #3 if you need more accuracy. +### Numeric Data Types and Precision -Tests ------ - -Geocoder comes with a test suite (just run `rake test`) that mocks ActiveRecord and is focused on testing the aspects of Geocoder that do not involve executing database queries. Geocoder uses many database engine-specific queries which must be tested against all supported databases (SQLite, MySQL, etc). Ideally this involves creating a full, working Rails application, and that seems beyond the scope of the included test suite. As such, I have created a separate repository which includes a full-blown Rails application and some utilities for easily running tests against multiple environments: - -http://github.com/alexreisner/geocoder_test - - -Error Handling --------------- - -By default Geocoder will rescue any exceptions raised by calls to a geocoding service and return an empty array. You can override this on a per-exception basis, and also have Geocoder raise its own exceptions for certain events (eg: API quota exceeded) by using the `:always_raise` option: - - Geocoder.configure(:always_raise => [SocketError, Timeout::Error]) - -You can also do this to raise all exceptions: - - Geocoder.configure(:always_raise => :all) - -The raise-able exceptions are: - - SocketError - Timeout::Error - Geocoder::OverQueryLimitError - Geocoder::RequestDenied - Geocoder::InvalidRequest - Geocoder::InvalidApiKey - Geocoder::ServiceUnavailable +Geocoder works with any numeric data type (e.g. float, double, decimal) on which trig (and other mathematical) functions can be performed. -Note that only a few of the above exceptions are raised by any given lookup, so there's no guarantee if you configure Geocoder to raise `ServiceUnavailable` that it will actually be raised under those conditions (because most APIs don't return 503 when they should; you may get a `Timeout::Error` instead). Please see the source code for your particular lookup for details. +A summary of the relationship between geographic precision and the number of decimal places in latitude and longitude degree values is available on [Wikipedia](http://en.wikipedia.org/wiki/Decimal_degrees#Accuracy). As an example: at the equator, latitude/longitude values with 4 decimal places give about 11 metres precision, whereas 5 decimal places gives roughly 1 metre precision. Troubleshooting @@ -1215,26 +638,23 @@ For the most part, the speed of geocoding requests has little to do with the Geo Take a look at the server's raw response. You can do this by getting the request URL in an app console: - Geocoder::Lookup.get(:google).query_url(Geocoder::Query.new("...")) + Geocoder::Lookup.get(:nominatim).query_url(Geocoder::Query.new("...")) -Replace `:google` with the lookup you are using and replace `...` with the address you are trying to geocode. Then visit the returned URL in your web browser. Often the API will return an error message that helps you resolve the problem. If, after reading the raw response, you believe there is a problem with Geocoder, please post an issue and include both the URL and raw response body. +Replace `:nominatim` with the lookup you are using and replace `...` with the address you are trying to geocode. Then visit the returned URL in your web browser. Often the API will return an error message that helps you resolve the problem. If, after reading the raw response, you believe there is a problem with Geocoder, please post an issue and include both the URL and raw response body. You can also fetch the response in the console: - Geocoder::Lookup.get(:google).send(:fetch_raw_data, Geocoder::Query.new("...")) - - -Reporting Issues ----------------- + Geocoder::Lookup.get(:nominatim).send(:fetch_raw_data, Geocoder::Query.new("...")) -When reporting an issue, please list the version of Geocoder you are using and any relevant information about your application (Rails version, database type and version, etc). Also avoid vague language like "it doesn't work." Please describe as specifically as you can what behavior you are actually seeing (eg: an error message? a nil return value?). -Please DO NOT use GitHub issues to ask questions about how to use Geocoder. Sites like [StackOverflow](http://www.stackoverflow.com/) are a better forum for such discussions. +Known Issues +------------ +### Using `count` with Rails 4.1+ -### Known Issues +Due to [a change in ActiveRecord's `count` method](https://github.com/rails/rails/pull/10710) you will need to use `count(:all)` to explicitly count all columns ("*") when using a `near` scope. Using `near` and calling `count` with no argument will cause exceptions in many cases. -#### Using `near` with `includes` +### Using `near` with `includes` You cannot use the `near` scope with another scope that provides an `includes` option because the `SELECT` clause generated by `near` will overwrite it (or vice versa). @@ -1242,7 +662,7 @@ Instead of using `includes` to reduce the number of database queries, try using # Pass a :select option to the near scope to get the columns you want. # Instead of City.near(...).includes(:venues), try: - City.near("Omaha, NE", 20, :select => "cities.*, venues.*").joins(:venues) + City.near("Omaha, NE", 20, select: "cities.*, venues.*").joins(:venues) # This preload call will normally trigger two queries regardless of the # number of results; one query on hotels, and one query on administrators. @@ -1251,11 +671,19 @@ Instead of using `includes` to reduce the number of database queries, try using If anyone has a more elegant solution to this problem I am very interested in seeing it. -#### Using `near` with objects close to the 180th meridian +### Using `near` with objects close to the 180th meridian The `near` method will not look across the 180th meridian to find objects close to a given point. In practice this is rarely an issue outside of New Zealand and certain surrounding islands. This problem does not exist with the zero-meridian. The problem is due to a shortcoming of the Haversine formula which Geocoder uses to calculate distances. +Reporting Issues +---------------- + +When reporting an issue, please list the version of Geocoder you are using and any relevant information about your application (Rails version, database type and version, etc). Please describe as specifically as you can what behavior you are seeing (eg: an error message? a nil return value?). + +Please DO NOT use GitHub issues to ask questions about how to use Geocoder. Sites like [StackOverflow](http://www.stackoverflow.com/) are a better forum for such discussions. + + Contributing ------------ @@ -1273,4 +701,4 @@ For all contributions, please respect the following guidelines: * If your pull request is merged, please do not ask for an immediate release of the gem. There are many factors contributing to when releases occur (remember that they affect thousands of apps with Geocoder in their Gemfiles). If necessary, please install from the Github source until the next official release. -Copyright (c) 2009-15 Alex Reisner, released under the MIT license +Copyright :copyright: 2009-2020 Alex Reisner, released under the MIT license. diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md new file mode 100644 index 000000000..f78f46a6b --- /dev/null +++ b/README_API_GUIDE.md @@ -0,0 +1,608 @@ +Guide to Geocoding APIs +======================= + +This is a list of geocoding APIs supported by the Geocoder gem. Before using any API in a production environment, please read its official Terms of Service (links below). + +Table of Contents +----------------- + +* [Global Street Address Lookups](#global-street-address-lookups) +* [Regional Street Address Lookups](#regional-street-address-lookups) +* [IP Address Lookups](#ip-address-lookups) +* [Local IP Address Lookups](#local-ip-address-lookups) + +Global Street Address Lookups +----------------------------- + +### Nominatim (`:nominatim`) + +* **API key**: none +* **Quota**: 1 request/second +* **Region**: world +* **SSL support**: yes +* **Languages**: ? +* **Documentation**: http://wiki.openstreetmap.org/wiki/Nominatim +* **Terms of Service**: https://operations.osmfoundation.org/policies/nominatim/ +* **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) + +### Google (`:google`) + +* **API key**: required +* **Key signup**: https://developers.google.com/maps/documentation/geocoding/usage-and-billing +* **Quota**: pay-as-you-go pricing; 50 requests/second +* **Region**: world +* **SSL support**: yes (required if key is used) +* **Languages**: see https://developers.google.com/maps/faq#languagesupport +* **Extra params**: + * `:bounds` - pass SW and NE coordinates as an array of two arrays to bias results towards a viewport + * `:google_place_id` - pass `true` if search query is a Google Place ID +* **Documentation**: https://developers.google.com/maps/documentation/geocoding/intro +* **Terms of Service**: http://code.google.com/apis/maps/terms.html#section_10_12 +* **Limitations**: "You can display Geocoding API results on a Google Map, or without a map. If you want to display Geocoding API results on a map, then these results must be displayed on a Google Map. ... If your application displays data from the Geocoding API on a page or view that does not also display a Google Map, you must show a Powered by Google logo with that data. ... ...you must not pre-fetch, index, store, or cache any Content except under the limited conditions stated in the terms." (see: https://developers.google.com/maps/documentation/geocoding/policies) + +### Google Maps API for Work (`:google_premier`) + +Similar to `:google`, with the following differences: + +* **API key**: required, plus client and channel (set `Geocoder.configure(lookup: :google_premier, api_key: [key, client, channel])`) +* **Key signup**: https://developers.google.com/maps/premium/ +* **Quota**: 100,000 requests/24 hrs, 10 requests/second + +### Google Places Details (`:google_places_details`) + +The [Google Places Details API](https://developers.google.com/places/documentation/details) is not, strictly speaking, a geocoding service. It accepts a Google `place_id` and returns address information, ratings and reviews. A `place_id` can be obtained from the Google Places Search lookup (`:google_places_search`) and should be passed to Geocoder as the first search argument: `Geocoder.search("ChIJhRwB-yFawokR5Phil-QQ3zM", lookup: :google_places_details)`. + +* **API key**: required +* **Key signup**: https://code.google.com/apis/console/ +* **Quota**: 1,000 request/day, 100,000 after credit card authentication +* **Region**: world +* **SSL support**: yes +* **Languages**: ar, eu, bg, bn, ca, cs, da, de, el, en, en-AU, en-GB, es, eu, fa, fi, fil, fr, gl, gu, hi, hr, hu, id, it, iw, ja, kn, ko, lt, lv, ml, mr, nl, no, pl, pt, pt-BR, pt-PT, ro, ru, sk, sl, sr, sv, tl, ta, te, th, tr, uk, vi, zh-CN, zh-TW (see http://spreadsheets.google.com/pub?key=p9pdwsai2hDMsLkXsoM05KQ&gid=1) +* **Documentation**: https://developers.google.com/places/documentation/details +* **Terms of Service**: https://developers.google.com/places/policies +* **Limitations**: "If your application displays Places API data on a page or view that does not also display a Google Map, you must show a "Powered by Google" logo with that data." + +### Google Places Search (`:google_places_search`) + +The [Google Places Search API](https://developers.google.com/places/web-service/search) is the geocoding service of Google Places API. It returns very limited location data, but it also returns a `place_id` which can be used with Google Place Details to get more detailed information. For a comparison between this and the regular Google Geocoding API, see https://maps-apis.googleblog.com/2016/11/address-geocoding-in-google-maps-apis.html + +* Same specifications as Google Places Details (see above). + +### Bing (`:bing`) + +* **API key**: required (set `Geocoder.configure(lookup: :bing, api_key: key)`) +* **Key signup**: https://www.microsoft.com/maps/create-a-bing-maps-key.aspx +* **Quota**: 50,0000 requests/day (Windows app), 125,000 requests/year (non-Windows app) +* **Region**: world +* **SSL support**: no +* **Languages**: The preferred language of address elements in the result. Language code must be provided according to RFC 4647 standard. +* **Documentation**: http://msdn.microsoft.com/en-us/library/ff701715.aspx +* **Terms of Service**: http://www.microsoft.com/maps/product/terms.html +* **Limitations**: No country codes or state names. Must be used on "public-facing, non-password protected web sites," "in conjunction with Bing Maps or an application that integrates Bing Maps." + +### PickPoint (`:pickpoint`) + +* **API key**: required +* **Key signup**: [https://pickpoint.io](https://pickpoint.io) +* **Quota**: 2500 requests / day for free non-commercial usage, commercial plans are [available](https://pickpoint.io/#pricing). No rate limit. +* **Region**: world +* **SSL support**: required +* **Languages**: worldwide +* **Documentation**: [https://pickpoint.io/api-reference](https://pickpoint.io/api-reference) +* **Limitations**: [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://www.openstreetmap.org/copyright) + +### LocationIQ (`:location_iq`) + +* **API key**: required +* **Quota**: 60 requests/minute (2 req/sec, 10k req/day), then [ability to purchase more](http://locationiq.org/#pricing) +* **Region**: world +* **SSL support**: yes +* **Languages**: ? +* **Documentation**: https://locationiq.org/#docs +* **Terms of Service**: https://unwiredlabs.com/tos +* **Limitations**: [Data licensed under Open Database License (ODbL) (you must provide attribution).](https://www.openstreetmap.org/copyright) + +### OpenCageData (`:opencagedata`) + +* **API key**: required +* **Key signup**: https://opencagedata.com +* **Quota**: 2500 requests / day, then [ability to purchase more](https://opencagedata.com/pricing) +* **Region**: world +* **SSL support**: yes +* **Languages**: worldwide +* **Documentation**: https://opencagedata.com/api +* **Limitations**: [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://www.openstreetmap.org/copyright) + +### Yandex (`:yandex`) + +* **API key**: optional, but without it lookup is territorially limited +* **Quota**: 25000 requests / day +* **Region**: world with API key, else restricted to Russia, Ukraine, Belarus, Kazakhstan, Georgia, Abkhazia, South Ossetia, Armenia, Azerbaijan, Moldova, Turkmenistan, Tajikistan, Uzbekistan, Kyrgyzstan and Turkey +* **SSL support**: HTTPS only +* **Languages**: Russian, Belarusian, Ukrainian, English, Turkish (only for maps of Turkey) +* **Documentation**: http://api.yandex.com.tr/maps/doc/intro/concepts/intro.xml +* **Terms of Service**: http://api.yandex.com.tr/maps/doc/intro/concepts/intro.xml#rules +* **Limitations**: ? + +### Mapbox (`:mapbox`) + +* **API key**: required +* **Dataset**: Uses `mapbox.places` dataset by default. Specify the `mapbox.places-permanent` dataset by setting: `Geocoder.configure(mapbox: {dataset: "mapbox.places-permanent"})` +* **Key signup**: https://www.mapbox.com/pricing/ +* **Quota**: depends on plan +* **Region**: complete coverage of US and Canada, partial coverage elsewhere (see for details: https://www.mapbox.com/developers/api/geocoding/#coverage) +* **SSL support**: yes +* **Languages**: English +* **Extra params** (see Mapbox docs for more): + * `:country` - restrict results to a specific country, e.g., `us` or `ca` + * `:types` - restrict results to categories such as `address`, + `neighborhood`, `postcode` + * `:proximity` - bias results toward a `lng,lat`, e.g., + `params: { proximity: "-84.0,42.5" }` +* **Documentation**: https://www.mapbox.com/developers/api/geocoding/ +* **Terms of Service**: https://www.mapbox.com/tos/ +* **Limitations**: For `mapbox.places` dataset, must be displayed on a Mapbox map; Cache results for up to 30 days. For `mapbox.places-permanent` dataset, depends on plan. +* **Notes**: Currently in public beta. + +### Mapquest (`:mapquest`) + +* **API key**: required +* **Key signup**: https://developer.mapquest.com/plans +* **Quota**: ? +* **HTTP Headers**: when using the licensed API you can specify a referer like so: + `Geocoder.configure(http_headers: { "Referer" => "http://foo.com" })` +* **Region**: world +* **SSL support**: no +* **Languages**: English +* **Documentation**: http://www.mapquestapi.com/geocoding/ +* **Terms of Service**: http://info.mapquest.com/terms-of-use/ +* **Limitations**: ? +* **Notes**: You can use the open (non-licensed) API by setting: `Geocoder.configure(mapquest: {open: true})` (defaults to licensed version) + +### Here/Nokia (`:here`) + +* **API key**: required +* **Quota**: Depending on the API key +* **Region**: world +* **SSL support**: yes +* **Languages**: The preferred language of address elements in the result. Language code must be provided according to RFC 4647 standard. +* **Extra params**: + * `:bounds` - pass NW and SE coordinates as an array of two arrays to bias results towards a viewport + * `:country` - pass the country or list of countries using the country code (3 bytes, ISO 3166-1-alpha-3) or the country name, to filter the results +* **Documentation**: http://developer.here.com/rest-apis/documentation/geocoder +* **Terms of Service**: http://developer.here.com/faqs#l&t +* **Limitations**: ? + +### ESRI (`:esri`) + +* **API key**: optional (set `Geocoder.configure(esri: {api_key: ["client_id", "client_secret"]})`) +* **Quota**: Required for some scenarios (see Terms of Service) +* **Region**: world +* **SSL support**: yes +* **Languages**: English +* **Documentation**: https://developers.arcgis.com/rest/geocode/api-reference/overview-world-geocoding-service.htm +* **Terms of Service**: http://www.esri.com/legal/software-license +* **Limitations**: Requires API key if results will be stored. Using API key will also remove rate limit. +* **Notes**: You can specify which projection you want to use by setting, for example: `Geocoder.configure(esri: {outSR: 102100})`. If you will store results, set the flag and provide API key: `Geocoder.configure(esri: {api_key: ["client_id", "client_secret"], for_storage: true})`. If you want to, you can also supply an ESRI token directly: `Geocoder.configure(esri: {token: Geocoder::EsriToken.new('TOKEN', Time.now + 1.day})` + +### Pelias (`:pelias`) + +* **API key**: configurable (self-hosted service) +* **Quota**: none (self-hosted service) +* **Region**: world +* **SSL support**: yes +* **Languages**: en; see https://mapzen.com/documentation/search/language-codes/ +* **Documentation**: http://pelias.io/ +* **Terms of Service**: http://pelias.io/data_licenses.html +* **Limitations**: See terms +* **Notes**: Configure your self-hosted pelias with the `endpoint` option: `Geocoder.configure(lookup: :pelias, api_key: 'your_api_key', pelias: {endpoint: 'self.hosted/pelias'})`. Defaults to `localhost`. + +### Data Science Toolkit (`:dstk`) + +Data Science Toolkit provides an API whose response format is like Google's but which can be set up as a privately hosted service. + +* **API key**: none +* **Quota**: No quota if you are self-hosting the service. +* **Region**: world +* **SSL support**: ? +* **Languages**: en +* **Documentation**: http://www.datasciencetoolkit.org/developerdocs +* **Terms of Service**: http://www.datasciencetoolkit.org/developerdocs#googlestylegeocoder +* **Limitations**: No reverse geocoding. +* **Notes**: If you are hosting your own DSTK server you will need to configure the host name, eg: `Geocoder.configure(lookup: :dstk, dstk: {host: "localhost:4567"})`. + +### OSM Names (`:osmnames`) + +Open source geocoding engine which can be self-hosted. MapTiler.com hosts an installation for use with API key. + +* **API key**: required if not self-hosting (see https://www.maptiler.com/cloud/plans/) +* **Quota**: none if self-hosting; 100,000/mo with MapTiler free plan (more with paid) +* **Region**: world +* **SSL support**: yes +* **Languages**: English +* **Documentation**: https://osmnames.org/ (open source project), https://cloud.maptiler.com/geocoding/ (MapTiler) +* **Terms of Service**: https://www.maptiler.com/terms/ +* **Notes**: To use self-hosted service, set the `:host` option in `Geocoder.configure`. + + +Regional Street Address Lookups +------------------------------- + +### Baidu (`:baidu`) + +* **API key**: required +* **Quota**: No quota limits for geocoding +* **Region**: China +* **SSL support**: no +* **Languages**: Chinese (Simplified) +* **Documentation**: http://developer.baidu.com/map/webservice-geocoding.htm +* **Terms of Service**: http://developer.baidu.com/map/law.htm +* **Limitations**: Only good for non-commercial use. For commercial usage please check http://developer.baidu.com/map/question.htm#qa0013 +* **Notes**: To use Baidu set `Geocoder.configure(lookup: :baidu, api_key: "your_api_key")`. + +### Tencent (`:tencent`) + +* **API key**: required +* **Key signup**: http://lbs.qq.com/console/mykey.html +* **Quota**: 10,000 free requests per day per key. 5 requests per second per key. For increased quota, one must first apply to become a corporate developer and then apply for increased quota. +* **Region**: China +* **SSL support**: yes +* **Languages**: Chinese (Simplified) +* **Documentation**: http://lbs.qq.com/webservice_v1/guide-geocoder.html (Standard) & http://lbs.qq.com/webservice_v1/guide-gcoder.html (Reverse) +* **Terms of Service**: http://lbs.qq.com/terms.html +* **Limitations**: Only works for locations in Greater China (mainland China, Hong Kong, Macau, and Taiwan). +* **Notes**: To use Tencent, set `Geocoder.configure(lookup: :tencent, api_key: "your_api_key")`. + +### Geocoder.ca (`:geocoder_ca`) + +* **API key**: none +* **Quota**: ? +* **Region**: US, Canada, Mexico +* **SSL support**: no +* **Languages**: English +* **Documentation**: https://geocoder.ca/?premium_api=1 +* **Terms of Service**: http://geocoder.ca/?terms=1 +* **Limitations**: "Under no circumstances can our data be re-distributed or re-sold by anyone to other parties without our written permission." + +### Geocodio (`:geocodio`) + +* **API key**: required +* **Quota**: 2,500 free requests/day then purchase $0.0005 for each, also has volume pricing and plans. +* **Region**: US & Canada +* **SSL support**: yes +* **Languages**: en +* **Documentation**: https://geocod.io/docs/ +* **Terms of Service**: https://geocod.io/terms-of-use/ +* **Limitations**: No restrictions on use + +### SmartyStreets (`:smarty_streets`) + +* **API key**: requires auth_id and auth_token (set `Geocoder.configure(api_key: [id, token])`) +* **Quota**: 250/month then purchase at sliding scale. +* **Region**: US +* **SSL support**: yes (required) +* **Languages**: en +* **Documentation**: http://smartystreets.com/kb/liveaddress-api/rest-endpoint +* **Terms of Service**: http://smartystreets.com/legal/terms-of-service +* **Limitations**: No reverse geocoding. + +### Geoportail.lu (`:geoportail_lu`) + +* **API key**: none +* **Quota**: none +* **Region**: Luxembourg +* **SSL support**: yes +* **Languages**: en +* **Documentation**: http://wiki.geoportail.lu/doku.php?id=en:api +* **Terms of Service**: http://wiki.geoportail.lu/doku.php?id=en:mcg_1 +* **Limitations**: ? + +### Bing (`:bing`) + +* **API key**: required (set `Geocoder.configure(lookup: :bing, api_key: key)`) +* **Key signup**: https://www.microsoft.com/maps/create-a-bing-maps-key.aspx +* **Quota**: 50,0000 requests/day (Windows app), 125,000 requests/year (non-Windows app) +* **Region**: world +* **SSL support**: no +* **Languages**: The preferred language of address elements in the result. Language code must be provided according to RFC 4647 standard. +* **Documentation**: http://msdn.microsoft.com/en-us/library/ff701715.aspx +* **Terms of Service**: http://www.microsoft.com/maps/product/terms.html +* **Limitations**: No country codes or state names. Must be used on "public-facing, non-password protected web sites," "in conjunction with Bing Maps or an application that integrates Bing Maps." + +### Ordnance Survey OpenNames (`:uk_ordnance_survey_names`) + +* **API key**: required (sign up at https://developer.ordnancesurvey.co.uk/os-names-api) +* **Quota**: 250,000 / month +* **Region**: England, Wales and Scotland +* **SSL support**: yes +* **Languages**: English +* **Documentation**: https://apidocs.os.uk/docs/os-names-overview +* **Terms of Service**: https://developer.ordnancesurvey.co.uk/os-api-framework-agreement +* **Limitations**: Only searches postcodes and placenames in England, Wales and Scotland + +### PostcodeAnywhere UK (`:postcode_anywhere_uk`) + +* **API key**: required +* **Quota**: Dependant on service plan? +* **Region**: UK +* **SSL support**: yes +* **Languages**: English +* **Documentation**: http://www.postcodeanywhere.co.uk/Support/WebService/Geocoding/UK/Geocode/2/ +* **Terms of Service**: ? +* **Limitations**: ? +* **Notes**: To use PostcodeAnywhere you must include an API key: `Geocoder.configure(lookup: :postcode_anywhere_uk, api_key: 'your_api_key')`. + +### LatLon.io (`:latlon`) + +* **API key**: required +* **Quota**: Depends on the user's plan (free and paid plans available) +* **Region**: US +* **SSL support**: yes +* **Languages**: en +* **Documentation**: https://latlon.io/documentation +* **Terms of Service**: ? +* **Limitations**: No restrictions on use + +### Base Adresse Nationale FR (`:ban_data_gouv_fr`) + +* **API key**: none +* **Quota**: none +* **Region**: France +* **SSL support**: yes +* **Languages**: en / fr +* **Documentation**: https://adresse.data.gouv.fr/api/ (in french) +* **Terms of Service**: https://adresse.data.gouv.fr/faq/ (in french) +* **Limitations**: [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://openstreetmap.fr/ban) + +### AMap (`:amap`) + +- **API key**: required +- **Quota**: 2000/day and 2000/minute for personal developer, 4000000/day and 60000/minute for enterprise developer, for geocoding requests +- **Region**: China +- **SSL support**: yes +- **Languages**: Chinese (Simplified) +- **Documentation**: http://lbs.amap.com/api/webservice/guide/api/georegeo +- **Terms of Service**: http://lbs.amap.com/home/terms/ +- **Limitations**: Only good for non-commercial use. For commercial usage please check http://lbs.amap.com/home/terms/ +- **Notes**: To use AMap set `Geocoder.configure(lookup: :amap, api_key: "your_api_key")`. + +### Nationaal Georegister Netherlands (`:nationaal_georegister_nl`) + +* **API key**: none +* **Quota**: ? +* **Region**: Netherlands +* **SSL support**: yes +* **Languages**: ? +* **Documentation**: http://geodata.nationaalgeoregister.nl/ +* **Terms of Service**: ? + + +IP Address Lookups +------------------ + +### IPInfo.io (`:ipinfo_io`) + +* **API key**: optional - see https://ipinfo.io/pricing +* **Quota**: 1,000/day without API key, 50,000/mo with a free account - more with a paid plan - see https://ipinfo.io/developers#rate-limits +* **Region**: world +* **SSL support**: yes +* **Languages**: English +* **Documentation**: https://ipinfo.io/developers +* **Terms of Service**: https://ipinfo.io/terms-of-service + +### FreeGeoIP (`:freegeoip`) - [DISCONTINUED](https://github.com/alexreisner/geocoder/wiki/Freegeoip-Discontinuation) + +* **API key**: none +* **Quota**: 15,000 requests per hour. After reaching the hourly quota, all of your requests will result in HTTP 403 (Forbidden) until it clears up on the next roll over. +* **Region**: world +* **SSL support**: no +* **Languages**: English +* **Documentation**: http://github.com/fiorix/freegeoip/blob/master/README.md +* **Terms of Service**: ? +* **Limitations**: ? +* **Notes**: If you are [running your own local instance of the FreeGeoIP service](https://github.com/fiorix/freegeoip) you can configure the host like this: `Geocoder.configure(freegeoip: {host: "..."})`. + +### Pointpin (`:pointpin`) + +* **API key**: required +* **Quota**: 50,000/mo for €9 through 1m/mo for €49 +* **Region**: world +* **SSL support**: yes +* **Languages**: English +* **Documentation**: https://pointp.in/docs/get-started +* **Terms of Service**: https://pointp.in/terms +* **Limitations**: ? +* **Notes**: To use Pointpin set `Geocoder.configure(ip_lookup: :pointpin, api_key: "your_pointpin_api_key")`. + +### Telize (`:telize`) + +* **API key**: required +* **Quota**: 1,000/day for $7/mo through 100,000/day for $100/mo +* **Region**: world +* **SSL support**: yes +* **Languages**: English +* **Documentation**: https://rapidapi.com/fcambus/api/telize +* **Terms of Service**: ? +* **Limitations**: ? +* **Notes**: To use Telize set `Geocoder.configure(ip_lookup: :telize, api_key: "your_api_key")`. Or configure your self-hosted telize with the `host` option: `Geocoder.configure(ip_lookup: :telize, telize: {host: "localhost"})`. + + +### MaxMind Legacy Web Services (`:maxmind`) + +* **API key**: required +* **Quota**: Request Packs can be purchased +* **Region**: world +* **SSL support**: yes +* **Languages**: English +* **Documentation**: http://dev.maxmind.com/geoip/legacy/web-services/ +* **Terms of Service**: ? +* **Limitations**: ? +* **Notes**: You must specify which MaxMind service you are using in your configuration. For example: `Geocoder.configure(maxmind: {service: :omni})`. + +### Baidu IP (`:baidu_ip`) + +* **API key**: required +* **Quota**: No quota limits for geocoding +* **Region**: China +* **SSL support**: no +* **Languages**: Chinese (Simplified) +* **Documentation**: http://developer.baidu.com/map/webservice-geocoding.htm +* **Terms of Service**: http://developer.baidu.com/map/law.htm +* **Limitations**: Only good for non-commercial use. For commercial usage please check http://developer.baidu.com/map/question.htm#qa0013 +* **Notes**: To use Baidu set `Geocoder.configure(lookup: :baidu_ip, api_key: "your_api_key")`. + +### MaxMind GeoIP2 Precision Web Services (`:maxmind_geoip2`) + +* **API key**: required +* **Quota**: Request Packs can be purchased +* **Region**: world +* **SSL support**: yes +* **Languages**: English +* **Documentation**: http://dev.maxmind.com/geoip/geoip2/web-services/ +* **Terms of Service**: ? +* **Limitations**: ? +* **Notes**: You must specify which MaxMind service you are using in your configuration, and also basic authentication. For example: `Geocoder.configure(maxmind_geoip2: {service: :country, basic_auth: {user: '', password: ''}})`. + +### Ipstack (`:ipstack`) + +* **API key**: required (see https://ipstack.com/product) +* **Quota**: 10,000 requests per month (with free API Key, 50,000/day and up for paid plans) +* **Region**: world +* **SSL support**: yes ( only with paid plan ) +* **Languages**: English, German, Spanish, French, Japanese, Portugues (Brazil), Russian, Chinese +* **Documentation**: https://ipstack.com/documentation +* **Terms of Service**: ? +* **Limitations**: ? +* **Notes**: To use Ipstack set `Geocoder.configure(ip_lookup: :ipstack, api_key: "your_ipstack_api_key")`. Supports the optional params: `:hostname`, `:security`, `:fields`, `:language` (see API documentation for details). + +### IP-API.com (`:ipapi_com`) + +* **API key**: optional - see https://members.ip-api.com +* **Quota**: 45/minute - unlimited with api key +* **Region**: world +* **SSL support**: no (not without access key - see https://members.ip-api.com) +* **Languages**: English +* **Documentation**: http://ip-api.com/docs/ +* **Terms of Service**: https://members.ip-api.com/legal + +### DB-IP.com (`:db_ip_com`) + +* **API key**: required +* **Quota**: 2,500/day (with free API Key, 50,000/day and up for paid API keys) +* **Region**: world +* **SSL support**: yes (with paid API keys - see https://db-ip.com/api/) +* **Languages**: English (English with free API key, multiple languages with paid API keys) +* **Documentation**: https://db-ip.com/api/doc.php +* **Terms of Service**: https://db-ip.com/tos.php + +### Ipdata.co (`:ipdata_co`) + +* **API key**: required, see: https://ipdata.co/pricing.html +* **Quota**: 1500/day for free, up to 600k with paid API keys +* **Region**: world +* **SSL support**: yes +* **Languages**: English +* **Documentation**: https://ipdata.co/docs.html +* **Terms of Service**: https://ipdata.co/terms.html +* **Limitations**: ? + +### IP2Location (`:ip2location`) + +* **API key**: optional (20 free demo queries per day) +* **Quota**: up to 100k credits with paid API key +* **Region**: world +* **SSL support**: yes +* **Languages**: English +* **Documentation**: https://www.ip2location.com/web-service +* **Terms of Service**: https://www.ip2location.com/web-service +* **Notes**: With the non-free version, specify your desired package: `Geocoder.configure(ip2location: {package: "WSX"})` (see API documentation for package details). + +### Ipregistry (`:ipregistry`) + +* **API key**: required (see https://ipregistry.co) +* **Quota**: first 100,000 requests are free, then you pay per request (see https://ipregistry.co/pricing) +* **Region**: world +* **SSL support**: yes +* **Languages**: English +* **Documentation**: https://ipregistry.co/docs +* **Terms of Service**: https://ipregistry.co/terms + +### Ipgeolocation (`:ipgeolocation`) + +* **API key**: required (see https://ipgeolocation.io/pricing) +* **Quota**: 1500/day (with free API Key) +* **Region**: world +* **SSL support**: yes +* **Languages**: English, German, Russian, Japanese, French, Chinese, Spanish, Czech, Italian +* **Documentation**: https://ipgeolocation.io/documentation +* **Terms of Service**: https://ipgeolocation/tos +* **Notes**: To use Ipgeolocation set `Geocoder.configure(ip_lookup: :ipgeolocation, api_key: "your_ipgeolocation_api_key", use_https:true)`. Supports the optional params: { excludes: "continent_code"}, {fields: "geo"}, {lang: "ru"}, {output: "xml"}, {include: "hostname"}, {ip: "174.7.116.0"}) (see API documentation for details). + +Local IP Address Lookups +------------------------ + +### MaxMind Local (`:maxmind_local`) - EXPERIMENTAL + +This lookup provides methods for geocoding IP addresses without making a call to a remote API (improves speed and availability). It works, but support is new and should not be considered production-ready. Please [report any bugs](https://github.com/alexreisner/geocoder/issues) you encounter. + +* **API key**: none (requires the GeoLite City database which can be downloaded from [MaxMind](http://dev.maxmind.com/geoip/legacy/geolite/)) +* **Quota**: none +* **Region**: world +* **SSL support**: N/A +* **Languages**: English +* **Documentation**: http://www.maxmind.com/en/city +* **Terms of Service**: ? +* **Limitations**: ? +* **Notes**: There are two supported formats for MaxMind local data: binary file, and CSV file imported into an SQL database. **You must download a database from MaxMind and set either the `:file` or `:package` configuration option for local lookups to work.** + +**To use a binary file** you must add the *geoip* (or *jgeoip* for JRuby) gem to your Gemfile or have it installed in your system, and specify the path of the MaxMind database in your configuration. For example: + + Geocoder.configure(ip_lookup: :maxmind_local, maxmind_local: {file: File.join('folder', 'GeoLiteCity.dat')}) + +**To use a CSV file** you must import it into an SQL database. The GeoLite *City* and *Country* packages are supported. Configure like so: + + Geocoder.configure(ip_lookup: :maxmind_local, maxmind_local: {package: :city}) + +You can generate ActiveRecord migrations and download and import data via provided rake tasks: + + # generate migration to create tables + rails generate geocoder:maxmind:geolite_city + + # download, unpack, and import data + rake geocoder:maxmind:geolite:load PACKAGE=city + +You can replace `city` with `country` in any of the above tasks, generators, and configurations. + +### GeoLite2 (`:geoip2`) + +This lookup provides methods for geocoding IP addresses without making a call to a remote API (improves speed and availability). It works, but support is new and should not be considered production-ready. Please [report any bugs](https://github.com/alexreisner/geocoder/issues) you encounter. + +* **API key**: none (requires a GeoIP2 or free GeoLite2 City or Country binary database which can be downloaded from [MaxMind](http://dev.maxmind.com/geoip/geoip2/)) +* **Quota**: none +* **Region**: world +* **SSL support**: N/A +* **Languages**: English +* **Documentation**: http://www.maxmind.com/en/city +* **Terms of Service**: ? +* **Limitations**: ? +* **Notes**: **You must download a binary database file from MaxMind and set the `:file` configuration option.** The CSV format databases are not yet supported since they are still in alpha stage. Set the path to the database file in your configuration: + + Geocoder.configure( + ip_lookup: :geoip2, + geoip2: { + file: File.join('folder', 'GeoLite2-City.mmdb') + } + ) + +You must add either the *[hive_geoip2](https://rubygems.org/gems/hive_geoip2)* gem (native extension that relies on libmaxminddb) or the *[maxminddb](http://rubygems.org/gems/maxminddb)* gem (pure Ruby implementation) to your Gemfile or have it installed in your system. The pure Ruby gem (maxminddb) will be used by default. To use `hive_geoip2`: + + Geocoder.configure( + ip_lookup: :geoip2, + geoip2: { + lib: 'hive_geoip2', + file: File.join('folder', 'GeoLite2-City.mmdb') + } + ) + + +Copyright (c) 2009-2020 Alex Reisner, released under the MIT license. diff --git a/Rakefile b/Rakefile index c7d106326..83de4cdd5 100644 --- a/Rakefile +++ b/Rakefile @@ -32,7 +32,7 @@ namespace :db do desc 'Drop the MySQL test databases' task :drop do - `mysqladmin --user=#{config['mysql']['username']} -f drop #{config['mysql']['database']}` + `mysql --user=#{config['mysql']['username']} -e "DROP DATABASE IF EXISTS #{config['mysql']['database']}"` end end @@ -44,7 +44,7 @@ namespace :db do desc 'Drop the PostgreSQL test databases' task :drop do - `dropdb #{config['postgres']['database']}` + `dropdb --if-exists #{config['postgres']['database']}` end end diff --git a/bin/console b/bin/console new file mode 100755 index 000000000..8a177d5b0 --- /dev/null +++ b/bin/console @@ -0,0 +1,13 @@ +#!/usr/bin/env ruby + +require 'bundler/setup' +require 'geocoder' + +if File.exist?("api_keys.yml") + require 'yaml' + @api_keys = YAML.load(File.read("api_keys.yml"), symbolize_names: true) + Geocoder.configure(@api_keys) +end + +require 'irb' +IRB.start diff --git a/examples/autoexpire_cache_redis.rb b/examples/autoexpire_cache_redis.rb index 1b67a9eee..e15c5f546 100644 --- a/examples/autoexpire_cache_redis.rb +++ b/examples/autoexpire_cache_redis.rb @@ -1,6 +1,8 @@ # This class implements a cache with simple delegation to the Redis store, but # when it creates a key/value pair, it also sends an EXPIRE command with a TTL. # It should be fairly simple to do the same thing with Memcached. +# Alternatively, this class could inherit from Redis, which would make most +# of the below methods unnecessary. class AutoexpireCacheRedis def initialize(store, ttl = 86400) @store = store @@ -8,11 +10,11 @@ def initialize(store, ttl = 86400) end def [](url) - @store.[](url) + @store.get(url) end def []=(url, value) - @store.[]=(url, value) + @store.set(url, value) @store.expire(url, @ttl) end @@ -25,4 +27,4 @@ def del(url) end end -Geocoder.configure(:cache => AutoexpireCacheRedis.new(Redis.new)) \ No newline at end of file +Geocoder.configure(:cache => AutoexpireCacheRedis.new(Redis.new)) diff --git a/gemfiles/Gemfile.rails3.2 b/gemfiles/Gemfile.rails3.2 deleted file mode 100644 index da838d6ab..000000000 --- a/gemfiles/Gemfile.rails3.2 +++ /dev/null @@ -1,43 +0,0 @@ -source "https://rubygems.org" - -group :development, :test do - gem 'rake' - gem 'mongoid', '2.6.0' - gem 'bson_ext', platforms: :ruby - gem 'geoip' - gem 'rubyzip' - gem 'rails', '>= 3.2' - gem 'test-unit' # needed for Ruby >=2.2.0 - - gem 'byebug', platforms: :mri - - platforms :jruby do - gem 'jruby-openssl' - gem 'jgeoip' - end - - platforms :rbx do - gem 'rubysl', '~> 2.0' - gem 'rubysl-test-unit' - end -end - -group :test do - platforms :ruby do - gem 'sqlite3' - gem 'sqlite_ext', '~> 1.5.0' - end - - gem 'webmock' - - platforms :ruby do - gem 'pg' - gem 'mysql2', '~> 0.3.11' - end - - platforms :jruby do - gem 'jdbc-mysql' - gem 'jdbc-sqlite3' - gem 'activerecord-jdbcpostgresql-adapter' - end -end diff --git a/gemfiles/Gemfile.rails4.1 b/gemfiles/Gemfile.rails4.1 index 34f96168b..b124ddc7f 100644 --- a/gemfiles/Gemfile.rails4.1 +++ b/gemfiles/Gemfile.rails4.1 @@ -9,8 +9,6 @@ group :development, :test do gem 'rails', '~> 4.1.13' gem 'test-unit' # needed for Ruby >=2.2.0 - gem 'byebug', platforms: :mri - platforms :jruby do gem 'jruby-openssl' gem 'jgeoip' @@ -24,20 +22,22 @@ end group :test do platforms :ruby, :mswin, :mingw do - gem 'sqlite3' + gem 'sqlite3', '~> 1.3.5' gem 'sqlite_ext', '~> 1.5.0' end - gem 'webmock' + gem 'public_suffix', '2.0.5' # webmock dependency + gem 'addressable', '2.5.2' # webmock dependency + gem 'webmock', '3.3.0' platforms :ruby do - gem 'pg' + gem 'pg', '~> 0.11' gem 'mysql2', '~> 0.3.11' end platforms :jruby do gem 'jdbc-mysql' gem 'jdbc-sqlite3' - gem 'activerecord-jdbcpostgresql-adapter' + gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3.0' end end diff --git a/gemfiles/Gemfile.rails5.0 b/gemfiles/Gemfile.rails5.0 index 07a4aaa87..1068091d3 100644 --- a/gemfiles/Gemfile.rails5.0 +++ b/gemfiles/Gemfile.rails5.0 @@ -9,8 +9,6 @@ group :development, :test do gem 'rails', '~> 5.0.1' gem 'test-unit' # needed for Ruby >=2.2.0 - gem 'byebug', platforms: :mri - platforms :jruby do gem 'jruby-openssl' gem 'jgeoip' @@ -24,14 +22,14 @@ end group :test do platforms :ruby, :mswin, :mingw do - gem 'sqlite3' + gem 'sqlite3', '~> 1.3.5' gem 'sqlite_ext', '~> 1.5.0' end gem 'webmock' platforms :ruby do - gem 'pg' + gem 'pg', '~> 0.18' gem 'mysql2', '~> 0.3.11' end diff --git a/gemfiles/Gemfile.ruby1.9.3 b/gemfiles/Gemfile.ruby1.9.3 deleted file mode 100644 index 05148196a..000000000 --- a/gemfiles/Gemfile.ruby1.9.3 +++ /dev/null @@ -1,34 +0,0 @@ -source "https://rubygems.org" - -group :development, :test do - gem 'rake' - gem 'mongoid', '2.6.0' - gem 'bson_ext', :platforms => :ruby - gem 'geoip' - gem 'rubyzip' - gem 'rails' - gem 'sqlite3' - gem 'sqlite_ext', '~> 1.5.0' - gem 'pg', '0.18.4' - gem 'mysql2', '~> 0.3.11' - gem 'public_suffix', '1.4.6' - - # i18n gem >=0.7.0 does not work with Ruby 1.9.2 - gem 'i18n', '0.6.1' - gem 'test-unit' # install newer version with omit() method - - gem 'debugger' - gem 'webmock', '2.3.2' - - platforms :jruby do - gem 'jruby-openssl' - gem 'jgeoip' - end - - platforms :rbx do - gem 'rubysl', '~> 2.0' - gem 'rubysl-test-unit' - end -end - -gemspec :path => '../' diff --git a/geocoder.gemspec b/geocoder.gemspec index 8bb7462e6..ed6955a26 100644 --- a/geocoder.gemspec +++ b/geocoder.gemspec @@ -5,7 +5,7 @@ require "geocoder/version" Gem::Specification.new do |s| s.name = "geocoder" - s.required_ruby_version = '>= 1.9.3' + s.required_ruby_version = '>= 2.0.0' s.version = Geocoder::VERSION s.platform = Gem::Platform::RUBY s.authors = ["Alex Reisner"] @@ -13,12 +13,11 @@ Gem::Specification.new do |s| s.homepage = "http://www.rubygeocoder.com" s.date = Date.today.to_s s.summary = "Complete geocoding solution for Ruby." - s.description = "Provides object geocoding (by street or IP address), reverse geocoding (coordinates to street address), distance queries for ActiveRecord and Mongoid, result caching, and more. Designed for Rails but works with Sinatra and other Rack frameworks too." + s.description = "Object geocoding (by street or IP address), reverse geocoding (coordinates to street address), distance queries for ActiveRecord and Mongoid, result caching, and more. Designed for Rails but works with Sinatra and other Rack frameworks too." s.files = Dir['CHANGELOG.md', 'LICENSE', 'README.md', 'examples/**/*', 'lib/**/*', 'bin/*'] s.require_paths = ["lib"] s.executables = ["geocode"] s.license = 'MIT' - s.metadata = { 'source_code_uri' => 'https://github.com/alexreisner/geocoder', 'changelog_uri' => 'https://github.com/alexreisner/geocoder/blob/master/CHANGELOG.md' diff --git a/lib/easting_northing.rb b/lib/easting_northing.rb new file mode 100644 index 000000000..0b9d2a9b4 --- /dev/null +++ b/lib/easting_northing.rb @@ -0,0 +1,171 @@ +module Geocoder + class EastingNorthing + attr_reader :easting, :northing, :lat_lng + + def initialize(opts) + @easting = opts[:easting] + @northing = opts[:northing] + + @lat_lng = to_WGS84(to_osgb_36) + end + + private + + def to_osgb_36 + osgb_fo = 0.9996012717 + northing0 = -100_000.0 + easting0 = 400_000.0 + phi0 = deg_to_rad(49.0) + lambda0 = deg_to_rad(-2.0) + a = 6_377_563.396 + b = 6_356_256.909 + eSquared = ((a * a) - (b * b)) / (a * a) + phi = 0.0 + lambda = 0.0 + n = (a - b) / (a + b) + m = 0.0 + phiPrime = ((northing - northing0) / (a * osgb_fo)) + phi0 + + while (northing - northing0 - m) >= 0.001 + m = + (b * osgb_fo)\ + * (((1 + n + ((5.0 / 4.0) * n * n) + ((5.0 / 4.0) * n * n * n))\ + * (phiPrime - phi0))\ + - (((3 * n) + (3 * n * n) + ((21.0 / 8.0) * n * n * n))\ + * Math.sin(phiPrime - phi0)\ + * Math.cos(phiPrime + phi0))\ + + ((((15.0 / 8.0) * n * n) + ((15.0 / 8.0) * n * n * n))\ + * Math.sin(2.0 * (phiPrime - phi0))\ + * Math.cos(2.0 * (phiPrime + phi0)))\ + - (((35.0 / 24.0) * n * n * n)\ + * Math.sin(3.0 * (phiPrime - phi0))\ + * Math.cos(3.0 * (phiPrime + phi0)))) + + phiPrime += (northing - northing0 - m) / (a * osgb_fo) + end + + v = a * osgb_fo * ((1.0 - eSquared * sin_pow_2(phiPrime))**-0.5) + rho = + a\ + * osgb_fo\ + * (1.0 - eSquared)\ + * ((1.0 - eSquared * sin_pow_2(phiPrime))**-1.5) + etaSquared = (v / rho) - 1.0 + vii = Math.tan(phiPrime) / (2 * rho * v) + viii = + (Math.tan(phiPrime) / (24.0 * rho * (v**3.0)))\ + * (5.0\ + + (3.0 * tan_pow_2(phiPrime))\ + + etaSquared\ + - (9.0 * tan_pow_2(phiPrime) * etaSquared)) + ix = + (Math.tan(phiPrime) / (720.0 * rho * (v**5.0)))\ + * (61.0\ + + (90.0 * tan_pow_2(phiPrime))\ + + (45.0 * tan_pow_2(phiPrime) * tan_pow_2(phiPrime))) + x = sec(phiPrime) / v + xi = + (sec(phiPrime) / (6.0 * v * v * v))\ + * ((v / rho) + (2 * tan_pow_2(phiPrime))) + xiii = + (sec(phiPrime) / (120.0 * (v**5.0)))\ + * (5.0\ + + (28.0 * tan_pow_2(phiPrime))\ + + (24.0 * tan_pow_2(phiPrime) * tan_pow_2(phiPrime))) + xiia = + (sec(phiPrime) / (5040.0 * (v**7.0)))\ + * (61.0\ + + (662.0 * tan_pow_2(phiPrime))\ + + (1320.0 * tan_pow_2(phiPrime) * tan_pow_2(phiPrime))\ + + (720.0\ + * tan_pow_2(phiPrime)\ + * tan_pow_2(phiPrime)\ + * tan_pow_2(phiPrime))) + phi = + phiPrime\ + - (vii * ((easting - easting0)**2.0))\ + + (viii * ((easting - easting0)**4.0))\ + - (ix * ((easting - easting0)**6.0)) + lambda = + lambda0\ + + (x * (easting - easting0))\ + - (xi * ((easting - easting0)**3.0))\ + + (xiii * ((easting - easting0)**5.0))\ + - (xiia * ((easting - easting0)**7.0)) + + [rad_to_deg(phi), rad_to_deg(lambda)] + end + + def to_WGS84(latlng) + latitude = latlng[0] + longitude = latlng[1] + + a = 6_377_563.396 + b = 6_356_256.909 + eSquared = ((a * a) - (b * b)) / (a * a) + + phi = deg_to_rad(latitude) + lambda = deg_to_rad(longitude) + v = a / Math.sqrt(1 - eSquared * sin_pow_2(phi)) + h = 0 + x = (v + h) * Math.cos(phi) * Math.cos(lambda) + y = (v + h) * Math.cos(phi) * Math.sin(lambda) + z = ((1 - eSquared) * v + h) * Math.sin(phi) + + tx = 446.448 + ty = -124.157 + tz = 542.060 + + s = -0.0000204894 + rx = deg_to_rad(0.00004172222) + ry = deg_to_rad(0.00006861111) + rz = deg_to_rad(0.00023391666) + + xB = tx + (x * (1 + s)) + (-rx * y) + (ry * z) + yB = ty + (rz * x) + (y * (1 + s)) + (-rx * z) + zB = tz + (-ry * x) + (rx * y) + (z * (1 + s)) + + a = 6_378_137.000 + b = 6_356_752.3141 + eSquared = ((a * a) - (b * b)) / (a * a) + + lambdaB = rad_to_deg(Math.atan(yB / xB)) + p = Math.sqrt((xB * xB) + (yB * yB)) + phiN = Math.atan(zB / (p * (1 - eSquared))) + + (1..10).each do |_i| + v = a / Math.sqrt(1 - eSquared * sin_pow_2(phiN)) + phiN1 = Math.atan((zB + (eSquared * v * Math.sin(phiN))) / p) + phiN = phiN1 + end + + phiB = rad_to_deg(phiN) + + [phiB, lambdaB] + end + + def deg_to_rad(degrees) + degrees / 180.0 * Math::PI + end + + def rad_to_deg(r) + (r / Math::PI) * 180 + end + + def sin_pow_2(x) + Math.sin(x) * Math.sin(x) + end + + def cos_pow_2(x) + Math.cos(x) * Math.cos(x) + end + + def tan_pow_2(x) + Math.tan(x) * Math.tan(x) + end + + def sec(x) + 1.0 / Math.cos(x) + end + end +end diff --git a/lib/generators/geocoder/config/templates/initializer.rb b/lib/generators/geocoder/config/templates/initializer.rb index 41d682f2f..0e6417303 100644 --- a/lib/generators/geocoder/config/templates/initializer.rb +++ b/lib/generators/geocoder/config/templates/initializer.rb @@ -1,8 +1,8 @@ Geocoder.configure( # Geocoding options # timeout: 3, # geocoding service timeout (secs) - # lookup: :google, # name of geocoding service (symbol) - # ip_lookup: :freegeoip, # name of IP address geocoding service (symbol) + # lookup: :nominatim, # name of geocoding service (symbol) + # ip_lookup: :ipinfo_io, # name of IP address geocoding service (symbol) # language: :en, # ISO-639 language code # use_https: false, # use HTTPS for lookup requests? (if supported) # http_proxy: nil, # HTTP proxy server (user:pass@host:port) diff --git a/lib/geocoder/cache.rb b/lib/geocoder/cache.rb index defb25612..9eb032a3a 100644 --- a/lib/geocoder/cache.rb +++ b/lib/geocoder/cache.rb @@ -68,7 +68,7 @@ def key_for(url) # that have non-nil values. # def keys - store.keys.select{ |k| k.match(/^#{prefix}/) and interpret(store[k]) } + store.keys.select{ |k| k.match(/^#{prefix}/) and self[k] } end ## diff --git a/lib/geocoder/calculations.rb b/lib/geocoder/calculations.rb index 84ab009c8..e70388cf1 100644 --- a/lib/geocoder/calculations.rb +++ b/lib/geocoder/calculations.rb @@ -154,7 +154,7 @@ def bearing_between(point1, point2, options = {}) # Translate a bearing (float) into a compass direction (string, eg "North"). # def compass_point(bearing, points = COMPASS_POINTS) - seg_size = 360 / points.size + seg_size = 360.0 / points.size points[((bearing + (seg_size / 2)) % 360) / seg_size] end diff --git a/lib/geocoder/cli.rb b/lib/geocoder/cli.rb index f4832a15d..2314aa187 100644 --- a/lib/geocoder/cli.rb +++ b/lib/geocoder/cli.rb @@ -97,7 +97,7 @@ def self.run(args, out = STDOUT) end if (result = Geocoder.search(query).first) - google = Geocoder::Lookup.get(:google) + nominatim = Geocoder::Lookup.get(:nominatim) lines = [ ["Latitude", result.latitude], ["Longitude", result.longitude], @@ -106,7 +106,7 @@ def self.run(args, out = STDOUT) ["State/province", result.state], ["Postal code", result.postal_code], ["Country", result.country], - ["Google map", google.map_link_url(result.coordinates)], + ["Map", nominatim.map_link_url(result.coordinates)], ] lines.each do |line| out << (line[0] + ": ").ljust(18) + line[1].to_s + "\n" diff --git a/lib/geocoder/configuration.rb b/lib/geocoder/configuration.rb index 8a53e9817..8e097a2d0 100644 --- a/lib/geocoder/configuration.rb +++ b/lib/geocoder/configuration.rb @@ -97,8 +97,8 @@ def set_defaults # geocoding options @data[:timeout] = 3 # geocoding service timeout (secs) - @data[:lookup] = :google # name of street address geocoding service (symbol) - @data[:ip_lookup] = :freegeoip # name of IP address geocoding service (symbol) + @data[:lookup] = :nominatim # name of street address geocoding service (symbol) + @data[:ip_lookup] = :ipinfo_io # name of IP address geocoding service (symbol) @data[:language] = :en # ISO-639 language code @data[:http_headers] = {} # HTTP headers for lookup @data[:use_https] = false # use HTTPS for lookup requests? (if supported) diff --git a/lib/geocoder/exceptions.rb b/lib/geocoder/exceptions.rb index 228c45b3a..2e6a21beb 100644 --- a/lib/geocoder/exceptions.rb +++ b/lib/geocoder/exceptions.rb @@ -1,4 +1,4 @@ -require 'timeout' # required for Ruby 1.9.3 +require 'timeout' module Geocoder diff --git a/lib/geocoder/ip_address.rb b/lib/geocoder/ip_address.rb index 9174f8d3a..466636a3b 100644 --- a/lib/geocoder/ip_address.rb +++ b/lib/geocoder/ip_address.rb @@ -1,13 +1,27 @@ require 'resolv' module Geocoder class IpAddress < String + PRIVATE_IPS = [ + '10.0.0.0/8', + '172.16.0.0/12', + '192.168.0.0/16', + ].map { |ip| IPAddr.new(ip) }.freeze + + def internal? + loopback? || private? + end def loopback? - valid? and (self == "0.0.0.0" or self.match(/\A127\./) or self == "::1") + valid? and !!(self == "0.0.0.0" or self.match(/\A127\./) or self == "::1") + end + + def private? + valid? && PRIVATE_IPS.any? { |ip| ip.include?(self) } end def valid? - !!((self =~ Resolv::IPv4::Regex) || (self =~ Resolv::IPv6::Regex)) + ip = self[/(?<=\[)(.*?)(?=\])/] || self + !!((ip =~ Resolv::IPv4::Regex) || (ip =~ Resolv::IPv6::Regex)) end end end diff --git a/lib/geocoder/lookup.rb b/lib/geocoder/lookup.rb index 2d7104190..51b69cc28 100644 --- a/lib/geocoder/lookup.rb +++ b/lib/geocoder/lookup.rb @@ -32,27 +32,28 @@ def street_services :google_places_search, :bing, :geocoder_ca, - :geocoder_us, :yandex, + :nationaal_georegister_nl, :nominatim, :mapbox, :mapquest, - :mapzen, + :uk_ordnance_survey_names, :opencagedata, - :ovi, :pelias, :pickpoint, :here, :baidu, + :tencent, :geocodio, :smarty_streets, - :okf, :postcode_anywhere_uk, + :postcodes_io, :geoportail_lu, :ban_data_gouv_fr, :test, :latlon, - :amap + :amap, + :osmnames ] end @@ -70,8 +71,13 @@ def ip_services :pointpin, :maxmind_geoip2, :ipinfo_io, + :ipregistry, :ipapi_com, - :db_ip_com + :ipdata_co, + :db_ip_com, + :ipstack, + :ip2location, + :ipgeolocation ] end diff --git a/lib/geocoder/lookups/amap.rb b/lib/geocoder/lookups/amap.rb index 6989f1bdc..ff2ac1803 100644 --- a/lib/geocoder/lookups/amap.rb +++ b/lib/geocoder/lookups/amap.rb @@ -12,13 +12,17 @@ def required_api_key_parts ["key"] end - def query_url(query) - path = query.reverse_geocode? ? 'regeo' : 'geo' - "http://restapi.amap.com/v3/geocode/#{path}?" + url_query_string(query) + def supported_protocols + [:http] end private # --------------------------------------------------------------- + def base_query_url(query) + path = query.reverse_geocode? ? 'regeo' : 'geo' + "http://restapi.amap.com/v3/geocode/#{path}?" + end + def results(query, reverse = false) return [] unless doc = fetch_data(query) case [doc['status'], doc['info']] diff --git a/lib/geocoder/lookups/baidu.rb b/lib/geocoder/lookups/baidu.rb index 65d38da08..597c00127 100644 --- a/lib/geocoder/lookups/baidu.rb +++ b/lib/geocoder/lookups/baidu.rb @@ -12,10 +12,6 @@ def required_api_key_parts ["key"] end - def query_url(query) - "#{protocol}://api.map.baidu.com/geocoder/v2/?" + url_query_string(query) - end - # HTTP only def supported_protocols [:http] @@ -23,26 +19,34 @@ def supported_protocols private # --------------------------------------------------------------- + def base_query_url(query) + "#{protocol}://api.map.baidu.com/geocoder/v2/?" + end + + def content_key + 'result' + end + def results(query, reverse = false) return [] unless doc = fetch_data(query) case doc['status'] when 0 - return [doc['result']] unless doc['result'].blank? + return [doc[content_key]] unless doc[content_key].blank? when 1, 3, 4 raise_error(Geocoder::Error, "server error.") || - Geocoder.log(:warn, "Baidu Geocoding API error: server error.") + Geocoder.log(:warn, "#{name} Geocoding API error: server error.") when 2 raise_error(Geocoder::InvalidRequest, "invalid request.") || - Geocoder.log(:warn, "Baidu Geocoding API error: invalid request.") + Geocoder.log(:warn, "#{name} Geocoding API error: invalid request.") when 5 raise_error(Geocoder::InvalidApiKey, "invalid api key") || - Geocoder.log(:warn, "Baidu Geocoding API error: invalid api key.") + Geocoder.log(:warn, "#{name} Geocoding API error: invalid api key.") when 101, 102, 200..299 raise_error(Geocoder::RequestDenied, "request denied") || - Geocoder.log(:warn, "Baidu Geocoding API error: request denied.") + Geocoder.log(:warn, "#{name} Geocoding API error: request denied.") when 300..399 raise_error(Geocoder::OverQueryLimitError, "over query limit.") || - Geocoder.log(:warn, "Baidu Geocoding API error: over query limit.") + Geocoder.log(:warn, "#{name} Geocoding API error: over query limit.") end return [] end diff --git a/lib/geocoder/lookups/baidu_ip.rb b/lib/geocoder/lookups/baidu_ip.rb index cbdaa47bc..e48af508a 100644 --- a/lib/geocoder/lookups/baidu_ip.rb +++ b/lib/geocoder/lookups/baidu_ip.rb @@ -1,50 +1,21 @@ -require 'geocoder/lookups/base' +require 'geocoder/lookups/baidu' require 'geocoder/results/baidu_ip' module Geocoder::Lookup - class BaiduIp < Base + class BaiduIp < Baidu def name "Baidu IP" end - def required_api_key_parts - ["key"] - end - - def query_url(query) - "#{protocol}://api.map.baidu.com/location/ip?" + url_query_string(query) - end + private # --------------------------------------------------------------- - # HTTP only - def supported_protocols - [:http] + def base_query_url(query) + "#{protocol}://api.map.baidu.com/location/ip?" end - private # --------------------------------------------------------------- - - def results(query, reverse = false) - return [] unless doc = fetch_data(query) - case doc['status'] - when 0 - return [doc['content']] unless doc['content'].blank? - when 1, 3, 4 - raise_error(Geocoder::Error, "server error.") || - Geocoder.log(:warn, "Baidu IP Geocoding API error: server error.") - when 2 - raise_error(Geocoder::InvalidRequest, "invalid request.") || - Geocoder.log(:warn, "Baidu IP Geocoding API error: invalid request.") - when 5 - raise_error(Geocoder::InvalidApiKey, "invalid api key.") || - Geocoder.log(:warn, "Baidu IP Geocoding API error: invalid api key.") - when 101, 102, 200..299 - raise_error(Geocoder::RequestDenied, "request denied.") || - Geocoder.log(:warn, "Baidu IP Geocoding API error: request denied.") - when 300..399 - raise_error(Geocoder::OverQueryLimitError, "over query limit") || - Geocoder.log(:warn, "Baidu IP Geocoding API error: over query limit.") - end - return [] + def content_key + 'content' end def query_url_params(query) diff --git a/lib/geocoder/lookups/ban_data_gouv_fr.rb b/lib/geocoder/lookups/ban_data_gouv_fr.rb index 0c577f053..13ee34dc0 100644 --- a/lib/geocoder/lookups/ban_data_gouv_fr.rb +++ b/lib/geocoder/lookups/ban_data_gouv_fr.rb @@ -14,13 +14,13 @@ def map_link_url(coordinates) "https://www.openstreetmap.org/#map=19/#{coordinates.join('/')}" end - def query_url(query) + private # --------------------------------------------------------------- + + def base_query_url(query) method = query.reverse_geocode? ? "reverse" : "search" - "#{protocol}://api-adresse.data.gouv.fr/#{method}/?" + url_query_string(query) + "#{protocol}://api-adresse.data.gouv.fr/#{method}/?" end - private # --------------------------------------------------------------- - def any_result?(doc) doc['features'].any? end @@ -86,6 +86,12 @@ def search_geocode_ban_fr_params(query) unless (citycode = query.options[:citycode]).nil? || !code_param_is_valid?(citycode) params[:citycode] = citycode.to_s end + unless (lat = query.options[:lat]).nil? || !latitude_is_valid?(lat) + params[:lat] = lat + end + unless (lon = query.options[:lon]).nil? || !longitude_is_valid?(lon) + params[:lon] = lon + end params end @@ -126,5 +132,12 @@ def code_param_is_valid?(param) (1..99999).include?(param.to_i) end + def latitude_is_valid?(param) + param.to_f <= 90 && param.to_f >= -90 + end + + def longitude_is_valid?(param) + param.to_f <= 180 && param.to_f >= -180 + end end end diff --git a/lib/geocoder/lookups/base.rb b/lib/geocoder/lookups/base.rb index 76abcfd07..3247486bf 100644 --- a/lib/geocoder/lookups/base.rb +++ b/lib/geocoder/lookups/base.rb @@ -4,7 +4,6 @@ unless defined?(ActiveSupport::JSON) begin - require 'rubygems' # for Ruby 1.8 require 'json' rescue LoadError raise LoadError, "Please install the 'json' or 'json_pure' gem to parse geocoder results." @@ -72,8 +71,12 @@ def required_api_key_parts ## # URL to use for querying the geocoding engine. # + # Subclasses should not modify this method. Instead they should define + # base_query_url and url_query_string. If absolutely necessary to + # subclss this method, they must also subclass #cache_key. + # def query_url(query) - fail + base_query_url(query) + url_query_string(query) end ## @@ -97,6 +100,14 @@ def supported_protocols private # ------------------------------------------------------------- + ## + # String which, when concatenated with url_query_string(query) + # produces the full query URL. Should include the "?" a the end. + # + def base_query_url(query) + fail + end + ## # An object with configuration data for this particular lookup. # @@ -147,7 +158,14 @@ def url_query_string(query) # something else (like the URL before OAuth encoding). # def cache_key(query) - query_url(query) + base_query_url(query) + hash_to_query(cache_key_params(query)) + end + + def cache_key_params(query) + # omit api_key and token because they may vary among requests + query_url_params(query).reject do |key,value| + key.to_s.match(/(key|token)/) + end end ## @@ -179,6 +197,8 @@ def fetch_data(query) raise_error(err) or Geocoder.log(:warn, "Geocoding API connection cannot be established.") rescue Errno::ECONNREFUSED => err raise_error(err) or Geocoder.log(:warn, "Geocoding API connection refused.") + rescue Geocoder::NetworkError => err + raise_error(err) or Geocoder.log(:warn, "Geocoding API connection is either unreacheable or reset by the peer") rescue Timeout::Error => err raise_error(err) or Geocoder.log(:warn, "Geocoding API not responding fast enough " + "(use Geocoder.configure(:timeout => ...) to set limit).") @@ -191,7 +211,10 @@ def parse_json(data) JSON.parse(data) end rescue - raise_error(ResponseParseError.new(data)) or Geocoder.log(:warn, "Geocoding API's response was not valid JSON: #{data}") + unless raise_error(ResponseParseError.new(data)) + Geocoder.log(:warn, "Geocoding API's response was not valid JSON") + Geocoder.log(:debug, "Raw response: #{data}") + end end ## diff --git a/lib/geocoder/lookups/bing.rb b/lib/geocoder/lookups/bing.rb index 53aaadf57..c2d0edcfc 100644 --- a/lib/geocoder/lookups/bing.rb +++ b/lib/geocoder/lookups/bing.rb @@ -16,24 +16,20 @@ def required_api_key_parts ["key"] end - def query_url(query) - base_url(query) + url_query_string(query) - end - private # --------------------------------------------------------------- - def base_url(query) - url = "#{protocol}://dev.virtualearth.net/REST/v1/Locations" - - if !query.reverse_geocode? + def base_query_url(query) + text = CGI.escape(query.sanitized_text.strip) + url = "#{protocol}://dev.virtualearth.net/REST/v1/Locations/" + if query.reverse_geocode? + url + "#{text}?" + else if r = query.options[:region] - url << "/#{r}" + url << "#{r}/" end # use the more forgiving 'unstructured' query format to allow special # chars, newlines, brackets, typos. - url + "?q=" + URI.escape(query.sanitized_text.strip) + "&" - else - url + "/#{URI.escape(query.sanitized_text.strip)}?" + url + "?q=#{text}&" end end @@ -44,6 +40,11 @@ def results(query) return doc['resourceSets'].first['estimatedTotal'] > 0 ? doc['resourceSets'].first['resources'] : [] elsif doc['statusCode'] == 401 and doc["authenticationResultCode"] == "InvalidCredentials" raise_error(Geocoder::InvalidApiKey) || Geocoder.log(:warn, "Invalid Bing API key.") + elsif doc['statusCode'] == 403 + raise_error(Geocoder::RequestDenied) || Geocoder.log(:warn, "Bing Geocoding API error: Forbidden Request") + elsif [500, 503].include?(doc['statusCode']) + raise_error(Geocoder::ServiceUnavailable) || + Geocoder.log(:warn, "Bing Geocoding API error: Service Unavailable") else Geocoder.log(:warn, "Bing Geocoding API error: #{doc['statusCode']} (#{doc['statusDescription']}).") end @@ -52,7 +53,8 @@ def results(query) def query_url_params(query) { - key: configuration.api_key + key: configuration.api_key, + language: (query.language || configuration.language) }.merge(super) end diff --git a/lib/geocoder/lookups/db_ip_com.rb b/lib/geocoder/lookups/db_ip_com.rb index bd7144d6e..7da241c03 100644 --- a/lib/geocoder/lookups/db_ip_com.rb +++ b/lib/geocoder/lookups/db_ip_com.rb @@ -16,15 +16,18 @@ def required_api_key_parts ['api_key'] end - def query_url(query) - query_params = if query.options[:params] - "?#{url_query_string(query)}" - end + private # ---------------------------------------------------------------- - "#{protocol}://api.db-ip.com/v2/#{configuration.api_key}/#{query.sanitized_text}#{query_params}" + def base_query_url(query) + "#{protocol}://api.db-ip.com/v2/#{configuration.api_key}/#{query.sanitized_text}?" end - private + ## + # Same as query_url but without the api key. + # + def cache_key(query) + "#{protocol}://api.db-ip.com/v2/#{query.sanitized_text}?" + hash_to_query(cache_key_params(query)) + end def results(query) return [] unless (doc = fetch_data(query)) diff --git a/lib/geocoder/lookups/dstk.rb b/lib/geocoder/lookups/dstk.rb index 681860530..f5c16cfc5 100644 --- a/lib/geocoder/lookups/dstk.rb +++ b/lib/geocoder/lookups/dstk.rb @@ -12,9 +12,11 @@ def name "Data Science Toolkit" end - def query_url(query) + private # ---------------------------------------------------------------- + + def base_query_url(query) host = configuration[:host] || "www.datasciencetoolkit.org" - "#{protocol}://#{host}/maps/api/geocode/json?" + url_query_string(query) + "#{protocol}://#{host}/maps/api/geocode/json?" end end end diff --git a/lib/geocoder/lookups/esri.rb b/lib/geocoder/lookups/esri.rb index 16bf95e0f..e80ba5437 100644 --- a/lib/geocoder/lookups/esri.rb +++ b/lib/geocoder/lookups/esri.rb @@ -4,15 +4,11 @@ module Geocoder::Lookup class Esri < Base - + def name "Esri" end - def query_url(query) - base_query_url(query) + url_query_string(query) - end - private # --------------------------------------------------------------- def base_query_url(query) @@ -34,17 +30,6 @@ def results(query) end end - def cache_key(query) - base_query_url(query) + hash_to_query(cache_key_params(query)) - end - - def cache_key_params(query) - # omit api_key and token because they may vary among requests - query_url_params(query).reject do |key,value| - [:api_key, :token].include?(key) - end - end - def query_url_params(query) params = { :f => "pjson", @@ -55,31 +40,58 @@ def query_url_params(query) else params[:text] = query.sanitized_text end - params[:token] = token - params[:forStorage] = configuration[:for_storage] if configuration[:for_storage] + + params[:token] = token(query) + + if for_storage_value = for_storage(query) + params[:forStorage] = for_storage_value + end params[:sourceCountry] = configuration[:source_country] if configuration[:source_country] + params[:preferredLabelValues] = configuration[:preferred_label_values] if configuration[:preferred_label_values] + params.merge(super) end - def token - create_and_save_token! if !valid_token_configured? and configuration.api_key - configuration[:token].to_s unless configuration[:token].nil? + def for_storage(query) + if query.options.has_key?(:for_storage) + query.options[:for_storage] + else + configuration[:for_storage] + end end - def valid_token_configured? - !configuration[:token].nil? and configuration[:token].active? + def token(query) + token_instance = if query.options[:token] + query.options[:token] + else + configuration[:token] + end + + if !valid_token_configured?(token_instance) && configuration.api_key + token_instance = create_and_save_token!(query) + end + + token_instance.to_s unless token_instance.nil? end - def create_and_save_token! - save_token!(create_token) + def valid_token_configured?(token_instance) + !token_instance.nil? && token_instance.active? end - def create_token - Geocoder::EsriToken.generate_token(*configuration.api_key) + def create_and_save_token!(query) + token_instance = create_token + + if query.options[:token] + query.options[:token] = token_instance + else + Geocoder.merge_into_lookup_config(:esri, token: token_instance) + end + + token_instance end - def save_token!(token_instance) - Geocoder.merge_into_lookup_config(:esri, token: token_instance) + def create_token + Geocoder::EsriToken.generate_token(*configuration.api_key) end end end diff --git a/lib/geocoder/lookups/freegeoip.rb b/lib/geocoder/lookups/freegeoip.rb index bad90279f..f16c24281 100644 --- a/lib/geocoder/lookups/freegeoip.rb +++ b/lib/geocoder/lookups/freegeoip.rb @@ -7,10 +7,10 @@ class Freegeoip < Base def name "FreeGeoIP" end - + def supported_protocols if configuration[:host] - [:http, :https] + [:https] else # use https for default host [:https] @@ -23,13 +23,17 @@ def query_url(query) private # --------------------------------------------------------------- + def cache_key(query) + query_url(query) + end + def parse_raw_data(raw_data) raw_data.match(/^404/) ? nil : super(raw_data) end def results(query) - # don't look up a loopback address, just return the stored result - return [reserved_result(query.text)] if query.loopback_ip_address? + # don't look up a loopback or private address, just return the stored result + return [reserved_result(query.text)] if query.internal_ip_address? # note: Freegeoip.net returns plain text "Not Found" on bad request (doc = fetch_data(query)) ? [doc] : [] end @@ -40,8 +44,8 @@ def reserved_result(ip) "city" => "", "region_code" => "", "region_name" => "", - "metrocode" => "", - "zipcode" => "", + "metro_code" => "", + "zip_code" => "", "latitude" => "0", "longitude" => "0", "country_name" => "Reserved", @@ -50,7 +54,7 @@ def reserved_result(ip) end def host - configuration[:host] || "freegeoip.net" + configuration[:host] || "freegeoip.app" end end end diff --git a/lib/geocoder/lookups/geocoder_ca.rb b/lib/geocoder/lookups/geocoder_ca.rb index 14d7492fb..98bb55471 100644 --- a/lib/geocoder/lookups/geocoder_ca.rb +++ b/lib/geocoder/lookups/geocoder_ca.rb @@ -8,12 +8,12 @@ def name "Geocoder.ca" end - def query_url(query) - "#{protocol}://geocoder.ca/?" + url_query_string(query) - end - private # --------------------------------------------------------------- + def base_query_url(query) + "#{protocol}://geocoder.ca/?" + end + def results(query) return [] unless doc = fetch_data(query) if doc['error'].nil? diff --git a/lib/geocoder/lookups/geocoder_us.rb b/lib/geocoder/lookups/geocoder_us.rb deleted file mode 100644 index dab787ab5..000000000 --- a/lib/geocoder/lookups/geocoder_us.rb +++ /dev/null @@ -1,43 +0,0 @@ -require 'geocoder/lookups/base' -require "geocoder/results/geocoder_us" - -module Geocoder::Lookup - class GeocoderUs < Base - - def name - "Geocoder.us" - end - - def supported_protocols - [:http] - end - - def query_url(query) - if configuration.api_key - "#{protocol}://#{configuration.api_key}@geocoder.us/member/service/csv/geocode?" + url_query_string(query) - else - "#{protocol}://geocoder.us/service/csv/geocode?" + url_query_string(query) - end - end - - private - - def results(query) - return [] unless doc = fetch_data(query) - if doc[0].to_s =~ /^(\d+)\:/ - return [] - else - return [doc.size == 5 ? ((doc[0..1] << nil) + doc[2..4]) : doc] - end - end - - def query_url_params(query) - (query.text =~ /^\d{5}(?:-\d{4})?$/ ? {:zip => query} : {:address => query.sanitized_text}).merge(super) - end - - def parse_raw_data(raw_data) - raw_data.chomp.split(',') - end - end -end - diff --git a/lib/geocoder/lookups/geocodio.rb b/lib/geocoder/lookups/geocodio.rb index 60c15957c..14e26554f 100644 --- a/lib/geocoder/lookups/geocodio.rb +++ b/lib/geocoder/lookups/geocodio.rb @@ -8,11 +8,6 @@ def name "Geocodio" end - def query_url(query) - path = query.reverse_geocode? ? "reverse" : "geocode" - "#{protocol}://api.geocod.io/v1/#{path}?#{url_query_string(query)}" - end - def results(query) return [] unless doc = fetch_data(query) return doc["results"] if doc['error'].nil? @@ -32,6 +27,11 @@ def results(query) private # --------------------------------------------------------------- + def base_query_url(query) + path = query.reverse_geocode? ? "reverse" : "geocode" + "#{protocol}://api.geocod.io/v1.3/#{path}?" + end + def query_url_params(query) { :api_key => configuration.api_key, diff --git a/lib/geocoder/lookups/geoportail_lu.rb b/lib/geocoder/lookups/geoportail_lu.rb index a5ff00ea9..bb35a0ee0 100644 --- a/lib/geocoder/lookups/geoportail_lu.rb +++ b/lib/geocoder/lookups/geoportail_lu.rb @@ -9,14 +9,14 @@ def name "Geoportail.lu" end - def query_url(query) - url_base_path(query) + url_query_string(query) - end - - private + private # --------------------------------------------------------------- - def url_base_path(query) - query.reverse_geocode? ? reverse_geocode_url_base_path : search_url_base_path + def base_query_url(query) + if query.reverse_geocode? + reverse_geocode_url_base_path + else + search_url_base_path + end end def search_url_base_path diff --git a/lib/geocoder/lookups/google.rb b/lib/geocoder/lookups/google.rb index d048a2639..b209f8d4b 100644 --- a/lib/geocoder/lookups/google.rb +++ b/lib/geocoder/lookups/google.rb @@ -21,12 +21,12 @@ def supported_protocols end end - def query_url(query) - "#{protocol}://maps.googleapis.com/maps/api/geocode/json?" + url_query_string(query) - end - private # --------------------------------------------------------------- + def base_query_url(query) + "#{protocol}://maps.googleapis.com/maps/api/geocode/json?" + end + def configure_ssl!(client) client.instance_eval { @ssl_context = OpenSSL::SSL::SSLContext.new @@ -52,11 +52,11 @@ def results(query) raise_error(Geocoder::OverQueryLimitError) || Geocoder.log(:warn, "#{name} API error: over query limit.") when "REQUEST_DENIED" - raise_error(Geocoder::RequestDenied) || - Geocoder.log(:warn, "#{name} API error: request denied.") + raise_error(Geocoder::RequestDenied, doc['error_message']) || + Geocoder.log(:warn, "#{name} API error: request denied (#{doc['error_message']}).") when "INVALID_REQUEST" - raise_error(Geocoder::InvalidRequest) || - Geocoder.log(:warn, "#{name} API error: invalid request.") + raise_error(Geocoder::InvalidRequest, doc['error_message']) || + Geocoder.log(:warn, "#{name} API error: invalid request (#{doc['error_message']}).") end return [] end diff --git a/lib/geocoder/lookups/google_places_details.rb b/lib/geocoder/lookups/google_places_details.rb index c4825f81e..5bc1b17e2 100644 --- a/lib/geocoder/lookups/google_places_details.rb +++ b/lib/geocoder/lookups/google_places_details.rb @@ -16,12 +16,12 @@ def supported_protocols [:https] end - def query_url(query) - "#{protocol}://maps.googleapis.com/maps/api/place/details/json?#{url_query_string(query)}" - end - private + def base_query_url(query) + "#{protocol}://maps.googleapis.com/maps/api/place/details/json?" + end + def results(query) return [] unless doc = fetch_data(query) diff --git a/lib/geocoder/lookups/google_places_search.rb b/lib/geocoder/lookups/google_places_search.rb index c8761d9a1..246103385 100644 --- a/lib/geocoder/lookups/google_places_search.rb +++ b/lib/geocoder/lookups/google_places_search.rb @@ -16,12 +16,12 @@ def supported_protocols [:https] end - def query_url(query) - "#{protocol}://maps.googleapis.com/maps/api/place/textsearch/json?#{url_query_string(query)}" - end - private + def base_query_url(query) + "#{protocol}://maps.googleapis.com/maps/api/place/textsearch/json?" + end + def query_url_google_params(query) { query: query.text, diff --git a/lib/geocoder/lookups/google_premier.rb b/lib/geocoder/lookups/google_premier.rb index 2867ede0b..c985bd875 100644 --- a/lib/geocoder/lookups/google_premier.rb +++ b/lib/geocoder/lookups/google_premier.rb @@ -11,7 +11,7 @@ def name end def required_api_key_parts - ["private key", "client", "channel"] + ["private key"] end def query_url(query) @@ -21,6 +21,16 @@ def query_url(query) private # --------------------------------------------------------------- + def cache_key(query) + "#{protocol}://maps.googleapis.com/maps/api/geocode/json?" + hash_to_query(cache_key_params(query)) + end + + def cache_key_params(query) + query_url_google_params(query).merge(super).reject do |k,v| + [:key, :client, :channel].include?(k) + end + end + def query_url_params(query) query_url_google_params(query).merge(super).merge( :key => nil, # don't use param inherited from Google lookup diff --git a/lib/geocoder/lookups/here.rb b/lib/geocoder/lookups/here.rb index 54148fbd4..27558682f 100644 --- a/lib/geocoder/lookups/here.rb +++ b/lib/geocoder/lookups/here.rb @@ -9,15 +9,19 @@ def name end def required_api_key_parts - ["app_id", "app_code"] + ['api_key'] end - def query_url(query) - "#{protocol}://#{if query.reverse_geocode? then 'reverse.' end}geocoder.api.here.com/6.2/#{if query.reverse_geocode? then 'reverse' end}geocode.json?" + url_query_string(query) + def supported_protocols + [:https] end private # --------------------------------------------------------------- + def base_query_url(query) + "#{protocol}://#{if query.reverse_geocode? then 'reverse.' end}geocoder.ls.hereapi.com/6.2/#{if query.reverse_geocode? then 'reverse' end}geocode.json?" + end + def results(query) return [] unless doc = fetch_data(query) return [] unless doc['Response'] && doc['Response']['View'] @@ -28,34 +32,36 @@ def results(query) [] end - def query_url_params(query) + def query_url_here_options(query, reverse_geocode) options = { - :gen=>4, - :app_id=>api_key, - :app_code=>api_code + gen: 9, + apikey: configuration.api_key, + language: (query.language || configuration.language) } + if reverse_geocode + options[:mode] = :retrieveAddresses + return options + end - if query.reverse_geocode? - super.merge(options).merge( - :prox=>query.sanitized_text, - :mode=>:retrieveAddresses - ) - else - super.merge(options).merge( - :searchtext=>query.sanitized_text - ) + unless (country = query.options[:country]).nil? + options[:country] = country end - end - def api_key - if a=configuration.api_key - return a.first if a.is_a?(Array) + unless (mapview = query.options[:bounds]).nil? + options[:mapview] = mapview.map{ |point| "%f,%f" % point }.join(';') end + options end - def api_code - if a=configuration.api_key - return a.last if a.is_a?(Array) + def query_url_params(query) + if query.reverse_geocode? + super.merge(query_url_here_options(query, true)).merge( + prox: query.sanitized_text + ) + else + super.merge(query_url_here_options(query, false)).merge( + searchtext: query.sanitized_text + ) end end end diff --git a/lib/geocoder/lookups/ip2location.rb b/lib/geocoder/lookups/ip2location.rb new file mode 100644 index 000000000..3b6481041 --- /dev/null +++ b/lib/geocoder/lookups/ip2location.rb @@ -0,0 +1,67 @@ +require 'geocoder/lookups/base' +require 'geocoder/results/ip2location' + +module Geocoder::Lookup + class Ip2location < Base + + def name + "IP2LocationApi" + end + + def supported_protocols + [:http, :https] + end + + private # ---------------------------------------------------------------- + + def base_query_url(query) + "#{protocol}://api.ip2location.com/?" + end + + def query_url_params(query) + params = super + if configuration.has_key?(:package) + params.merge!(package: configuration[:package]) + end + params + end + + def results(query) + # don't look up a loopback or private address, just return the stored result + return [reserved_result(query.text)] if query.internal_ip_address? + return [] unless doc = fetch_data(query) + if doc["response"] == "INVALID ACCOUNT" + raise_error(Geocoder::InvalidApiKey) || Geocoder.log(:warn, "INVALID ACCOUNT") + return [] + else + return [doc] + end + end + + def reserved_result(query) + { + "country_code" => "INVALID IP ADDRESS", + "country_name" => "INVALID IP ADDRESS", + "region_name" => "INVALID IP ADDRESS", + "city_name" => "INVALID IP ADDRESS", + "latitude" => "INVALID IP ADDRESS", + "longitude" => "INVALID IP ADDRESS", + "zip_code" => "INVALID IP ADDRESS", + "time_zone" => "INVALID IP ADDRESS", + "isp" => "INVALID IP ADDRESS", + "domain" => "INVALID IP ADDRESS", + "net_speed" => "INVALID IP ADDRESS", + "idd_code" => "INVALID IP ADDRESS", + "area_code" => "INVALID IP ADDRESS", + "weather_station_code" => "INVALID IP ADDRESS", + "weather_station_name" => "INVALID IP ADDRESS", + "mcc" => "INVALID IP ADDRESS", + "mnc" => "INVALID IP ADDRESS", + "mobile_brand" => "INVALID IP ADDRESS", + "elevation" => "INVALID IP ADDRESS", + "usage_type" => "INVALID IP ADDRESS" + } + end + + end +end diff --git a/lib/geocoder/lookups/ipapi_com.rb b/lib/geocoder/lookups/ipapi_com.rb index a799297a1..bf22c364f 100644 --- a/lib/geocoder/lookups/ipapi_com.rb +++ b/lib/geocoder/lookups/ipapi_com.rb @@ -8,17 +8,6 @@ def name "ip-api.com" end - def query_url(query) - domain = configuration.api_key ? "pro.ip-api.com" : "ip-api.com" - url_ = "#{protocol}://#{domain}/json/#{query.sanitized_text}" - - if (params = url_query_string(query)) && !params.empty? - url_ + "?" + params - else - url_ - end - end - def supported_protocols if configuration.api_key [:http, :https] @@ -27,8 +16,14 @@ def supported_protocols end end + private # ---------------------------------------------------------------- - private + def base_query_url(query) + domain = configuration.api_key ? "pro.ip-api.com" : "ip-api.com" + url = "#{protocol}://#{domain}/json/#{query.sanitized_text}" + url << "?" if not url_query_string(query).empty? + url + end def parse_raw_data(raw_data) if raw_data.chomp == "invalid key" @@ -39,7 +34,8 @@ def parse_raw_data(raw_data) end def results(query) - return [reserved_result(query.text)] if query.loopback_ip_address? + # don't look up a loopback or private address, just return the stored result + return [reserved_result(query.text)] if query.internal_ip_address? return [] unless doc = fetch_data(query) diff --git a/lib/geocoder/lookups/ipdata_co.rb b/lib/geocoder/lookups/ipdata_co.rb new file mode 100644 index 000000000..d061696bd --- /dev/null +++ b/lib/geocoder/lookups/ipdata_co.rb @@ -0,0 +1,62 @@ +require 'geocoder/lookups/base' +require 'geocoder/results/ipdata_co' + +module Geocoder::Lookup + class IpdataCo < Base + + def name + "ipdata.co" + end + + def supported_protocols + [:https] + end + + def query_url(query) + # Ipdata.co requires that the API key be sent as a query parameter. + # It no longer supports API keys sent as headers. + "#{protocol}://#{host}/#{query.sanitized_text}?api-key=#{configuration.api_key}" + end + + private # --------------------------------------------------------------- + + def cache_key(query) + query_url(query) + end + + def results(query) + # don't look up a loopback or private address, just return the stored result + return [reserved_result(query.text)] if query.internal_ip_address? + # note: Ipdata.co returns plain text on bad request + (doc = fetch_data(query)) ? [doc] : [] + end + + def reserved_result(ip) + { + "ip" => ip, + "city" => "", + "region_code" => "", + "region_name" => "", + "metrocode" => "", + "zipcode" => "", + "latitude" => "0", + "longitude" => "0", + "country_name" => "Reserved", + "country_code" => "RD" + } + end + + def host + "api.ipdata.co" + end + + def check_response_for_errors!(response) + if response.code.to_i == 403 + raise_error(Geocoder::RequestDenied) || + Geocoder.log(:warn, "Geocoding API error: 403 API key does not exist") + else + super(response) + end + end + end +end diff --git a/lib/geocoder/lookups/ipgeolocation.rb b/lib/geocoder/lookups/ipgeolocation.rb new file mode 100644 index 000000000..adfc655d3 --- /dev/null +++ b/lib/geocoder/lookups/ipgeolocation.rb @@ -0,0 +1,51 @@ +require 'geocoder/lookups/base' +require 'geocoder/results/ipgeolocation' + + +module Geocoder::Lookup + class Ipgeolocation < Base + + ERROR_CODES = { + 400 => Geocoder::RequestDenied, # subscription is paused + 401 => Geocoder::InvalidApiKey, # missing/invalid API key + 403 => Geocoder::InvalidRequest, # invalid IP address + 404 => Geocoder::InvalidRequest, # not found + 423 => Geocoder::InvalidRequest # bogon/reserved IP address + } + ERROR_CODES.default = Geocoder::Error + + def name + "Ipgeolocation" + end + + def supported_protocols + [:https] + end + + private # ---------------------------------------------------------------- + + def base_query_url(query) + "#{protocol}://api.ipgeolocation.io/ipgeo?" + end + def query_url_params(query) + { + ip: query.sanitized_text, + apiKey: configuration.api_key + }.merge(super) + end + + def results(query) + # don't look up a loopback or private address, just return the stored result + return [reserved_result(query.text)] if query.internal_ip_address? + [fetch_data(query)] + end + + def reserved_result(ip) + { + "ip" => ip, + "country_name" => "Reserved", + "country_code2" => "RD" + } + end + end +end diff --git a/lib/geocoder/lookups/ipinfo_io.rb b/lib/geocoder/lookups/ipinfo_io.rb index b7966d46c..ef0cdf0bc 100644 --- a/lib/geocoder/lookups/ipinfo_io.rb +++ b/lib/geocoder/lookups/ipinfo_io.rb @@ -8,47 +8,29 @@ def name "Ipinfo.io" end - def query_url(query) - if configuration.api_key - "#{protocol}://ipinfo.io/#{query.sanitized_text}/geo?" + url_query_string(query) - else - "#{protocol}://ipinfo.io/#{query.sanitized_text}/geo" - end - end + private # --------------------------------------------------------------- - # HTTPS available only for paid plans - def supported_protocols - if configuration.api_key - [:http, :https] - else - [:http] - end + def base_query_url(query) + url = "#{protocol}://ipinfo.io/#{query.sanitized_text}/geo" + url << "?" if configuration.api_key + url end - private # --------------------------------------------------------------- - def results(query) - # don't look up a loopback address, just return the stored result - return [reserved_result(query.text)] if query.loopback_ip_address? - if (doc = fetch_data(query)).nil? or doc['code'] == 401 or empty_result?(doc) + # don't look up a loopback or private address, just return the stored result + return [reserved_result(query.text)] if query.internal_ip_address? + + if !(doc = fetch_data(query)).is_a?(Hash) or doc['error'] [] else [doc] end end - def empty_result?(doc) - !doc.is_a?(Hash) or doc.keys == ["ip"] - end - def reserved_result(ip) { - "ip" => ip, - "city" => "", - "region" => "", - "country" => "", - "loc" => "0,0", - "postal" => "" + "ip" => ip, + "bogon" => true } end diff --git a/lib/geocoder/lookups/ipregistry.rb b/lib/geocoder/lookups/ipregistry.rb new file mode 100644 index 000000000..a0591a4f2 --- /dev/null +++ b/lib/geocoder/lookups/ipregistry.rb @@ -0,0 +1,68 @@ +require 'geocoder/lookups/base' +require 'geocoder/results/ipregistry' + +module Geocoder::Lookup + class Ipregistry < Base + + ERROR_CODES = { + 400 => Geocoder::InvalidRequest, + 401 => Geocoder::InvalidRequest, + 402 => Geocoder::OverQueryLimitError, + 403 => Geocoder::InvalidApiKey, + 451 => Geocoder::RequestDenied, + 500 => Geocoder::Error + } + ERROR_CODES.default = Geocoder::Error + + def name + "Ipregistry" + end + + def supported_protocols + [:https, :http] + end + + private + + def base_query_url(query) + "#{protocol}://#{host}/#{query.sanitized_text}?" + end + + def cache_key(query) + query_url(query) + end + + def host + configuration[:host] || "api.ipregistry.co" + end + + def query_url_params(query) + { + key: configuration.api_key + }.merge(super) + end + + def results(query) + # don't look up a loopback or private address, just return the stored result + return [reserved_result(query.text)] if query.internal_ip_address? + + return [] unless (doc = fetch_data(query)) + + if (error = doc['error']) + code = error['code'] + msg = error['message'] + raise_error(ERROR_CODES[code], msg ) || Geocoder.log(:warn, "Ipregistry API error: #{msg}") + return [] + end + [doc] + end + + def reserved_result(ip) + { + "ip" => ip, + "country_name" => "Reserved", + "country_code" => "RD" + } + end + end +end diff --git a/lib/geocoder/lookups/ipstack.rb b/lib/geocoder/lookups/ipstack.rb new file mode 100644 index 000000000..f01f15288 --- /dev/null +++ b/lib/geocoder/lookups/ipstack.rb @@ -0,0 +1,63 @@ +require 'geocoder/lookups/base' +require 'geocoder/results/ipstack' + +module Geocoder::Lookup + class Ipstack < Base + + ERROR_CODES = { + 404 => Geocoder::InvalidRequest, + 101 => Geocoder::InvalidApiKey, + 102 => Geocoder::Error, + 103 => Geocoder::InvalidRequest, + 104 => Geocoder::OverQueryLimitError, + 105 => Geocoder::RequestDenied, + 301 => Geocoder::InvalidRequest, + 302 => Geocoder::InvalidRequest, + 303 => Geocoder::RequestDenied, + } + ERROR_CODES.default = Geocoder::Error + + def name + "Ipstack" + end + + private # ---------------------------------------------------------------- + + def base_query_url(query) + "#{protocol}://#{host}/#{query.sanitized_text}?" + end + + def query_url_params(query) + { + access_key: configuration.api_key + }.merge(super) + end + + def results(query) + # don't look up a loopback or private address, just return the stored result + return [reserved_result(query.text)] if query.internal_ip_address? + + return [] unless doc = fetch_data(query) + + if error = doc['error'] + code = error['code'] + msg = error['info'] + raise_error(ERROR_CODES[code], msg ) || Geocoder.log(:warn, "Ipstack Geocoding API error: #{msg}") + return [] + end + [doc] + end + + def reserved_result(ip) + { + "ip" => ip, + "country_name" => "Reserved", + "country_code" => "RD" + } + end + + def host + configuration[:host] || "api.ipstack.com" + end + end +end diff --git a/lib/geocoder/lookups/latlon.rb b/lib/geocoder/lookups/latlon.rb index b496c9b84..cdc47ae38 100644 --- a/lib/geocoder/lookups/latlon.rb +++ b/lib/geocoder/lookups/latlon.rb @@ -12,12 +12,12 @@ def required_api_key_parts ["api_key"] end - def query_url(query) - "#{protocol}://latlon.io/api/v1/#{'reverse_' if query.reverse_geocode?}geocode?#{url_query_string(query)}" - end - private # --------------------------------------------------------------- + def base_query_url(query) + "#{protocol}://latlon.io/api/v1/#{'reverse_' if query.reverse_geocode?}geocode?" + end + def results(query) return [] unless doc = fetch_data(query) if doc['error'].nil? @@ -25,8 +25,7 @@ def results(query) # The API returned a 404 response, which indicates no results found elsif doc['error']['type'] == 'api_error' [] - elsif - doc['error']['type'] == 'authentication_error' + elsif doc['error']['type'] == 'authentication_error' raise_error(Geocoder::InvalidApiKey) || Geocoder.log(:warn, "LatLon.io service error: invalid API key.") else diff --git a/lib/geocoder/lookups/location_iq.rb b/lib/geocoder/lookups/location_iq.rb index 197e7696a..341055722 100644 --- a/lib/geocoder/lookups/location_iq.rb +++ b/lib/geocoder/lookups/location_iq.rb @@ -10,13 +10,23 @@ def name def required_api_key_parts ["api_key"] end - - def query_url(query) + + private # ---------------------------------------------------------------- + + def base_query_url(query) method = query.reverse_geocode? ? "reverse" : "search" - "#{protocol}://locationiq.org/v1/#{method}.php?key=#{configuration.api_key}&" + url_query_string(query) + "#{protocol}://#{configured_host}/v1/#{method}.php?" end - private + def query_url_params(query) + { + key: configuration.api_key + }.merge(super) + end + + def configured_host + configuration[:host] || "locationiq.org" + end def results(query) return [] unless doc = fetch_data(query) diff --git a/lib/geocoder/lookups/mapbox.rb b/lib/geocoder/lookups/mapbox.rb index 36b11b018..fa2f5753c 100644 --- a/lib/geocoder/lookups/mapbox.rb +++ b/lib/geocoder/lookups/mapbox.rb @@ -8,13 +8,12 @@ def name "Mapbox" end - def query_url(query) - path = "#{mapbox_search_term(query)}.json?#{url_query_string(query)}" - "#{protocol}://api.mapbox.com/geocoding/v5/#{dataset}/#{path}" - end - private # --------------------------------------------------------------- + def base_query_url(query) + "#{protocol}://api.mapbox.com/geocoding/v5/#{dataset}/#{mapbox_search_term(query)}.json?" + end + def results(query) return [] unless data = fetch_data(query) if data['features'] @@ -36,7 +35,9 @@ def mapbox_search_term(query) lat,lon = query.coordinates "#{CGI.escape lon},#{CGI.escape lat}" else - CGI.escape query.text.to_s + # truncate at first semicolon so Mapbox doesn't go into batch mode + # (see Github issue #1299) + CGI.escape query.text.to_s.split(';').first.to_s end end diff --git a/lib/geocoder/lookups/mapquest.rb b/lib/geocoder/lookups/mapquest.rb index 7f53c093e..d7081e10f 100644 --- a/lib/geocoder/lookups/mapquest.rb +++ b/lib/geocoder/lookups/mapquest.rb @@ -13,14 +13,13 @@ def required_api_key_parts ["key"] end - def query_url(query) + private # --------------------------------------------------------------- + + def base_query_url(query) domain = configuration[:open] ? "open" : "www" - url = "#{protocol}://#{domain}.mapquestapi.com/geocoding/v1/#{search_type(query)}?" - url + url_query_string(query) + "#{protocol}://#{domain}.mapquestapi.com/geocoding/v1/#{search_type(query)}?" end - private # --------------------------------------------------------------- - def search_type(query) query.reverse_geocode? ? "reverse" : "address" end diff --git a/lib/geocoder/lookups/mapzen.rb b/lib/geocoder/lookups/mapzen.rb deleted file mode 100644 index 0bb70d309..000000000 --- a/lib/geocoder/lookups/mapzen.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'geocoder/lookups/pelias' -require 'geocoder/results/mapzen' - -# https://mapzen.com/documentation/search/search/ for more information -module Geocoder::Lookup - class Mapzen < Pelias - def name - 'Mapzen' - end - - def endpoint - configuration[:endpoint] || 'search.mapzen.com' - end - end -end diff --git a/lib/geocoder/lookups/maxmind.rb b/lib/geocoder/lookups/maxmind.rb index 393a2bf85..c9ba59535 100644 --- a/lib/geocoder/lookups/maxmind.rb +++ b/lib/geocoder/lookups/maxmind.rb @@ -9,12 +9,12 @@ def name "MaxMind" end - def query_url(query) - "#{protocol}://geoip.maxmind.com/#{service_code}?" + url_query_string(query) - end - private # --------------------------------------------------------------- + def base_query_url(query) + "#{protocol}://geoip.maxmind.com/#{service_code}?" + end + ## # Return the name of the configured service, or raise an exception. # @@ -57,8 +57,8 @@ def services end def results(query) - # don't look up a loopback address, just return the stored result - return [reserved_result] if query.loopback_ip_address? + # don't look up a loopback or private address, just return the stored result + return [reserved_result] if query.internal_ip_address? doc = fetch_data(query) if doc and doc.is_a?(Array) if !data_contains_error?(doc) diff --git a/lib/geocoder/lookups/maxmind_geoip2.rb b/lib/geocoder/lookups/maxmind_geoip2.rb index ebe81a178..0640a251b 100644 --- a/lib/geocoder/lookups/maxmind_geoip2.rb +++ b/lib/geocoder/lookups/maxmind_geoip2.rb @@ -20,6 +20,10 @@ def query_url(query) private # --------------------------------------------------------------- + def cache_key(query) + query_url(query) + end + ## # Return the name of the configured service, or raise an exception. # @@ -28,11 +32,7 @@ def configured_service! return s else raise( - Geocoder::ConfigurationError, - "When using MaxMind GeoIP2 you MUST specify a service name and basic_auth: " + - "Geocoder.configure(:maxmind_geoip2 => {:service => ...}, " + - ":basic_auth => {:user ..., :password => ...}), " + - "where service is one of: #{services.inspect}" + Geocoder::ConfigurationError, "When using MaxMind GeoIP2 you must specify a service and credentials: Geocoder.configure(maxmind_geoip2: {service: ..., basic_auth: {user: ..., password: ...}}), where service is one of: #{services.inspect}" ) end end @@ -53,8 +53,9 @@ def services end def results(query) - # don't look up a loopback address - return [] if query.loopback_ip_address? + # don't look up a loopback or private address, just return the stored result + return [] if query.internal_ip_address? + doc = fetch_data(query) if doc if !data_contains_error?(doc) diff --git a/lib/geocoder/lookups/nationaal_georegister_nl.rb b/lib/geocoder/lookups/nationaal_georegister_nl.rb new file mode 100644 index 000000000..af1256ba1 --- /dev/null +++ b/lib/geocoder/lookups/nationaal_georegister_nl.rb @@ -0,0 +1,38 @@ +require 'geocoder/lookups/base' +require "geocoder/results/nationaal_georegister_nl" + +module Geocoder::Lookup + class NationaalGeoregisterNl < Base + + def name + 'Nationaal Georegister Nederland' + end + + private # --------------------------------------------------------------- + + def cache_key(query) + base_query_url(query) + hash_to_query(query_url_params(query)) + end + + def base_query_url(query) + "#{protocol}://geodata.nationaalgeoregister.nl/locatieserver/v3/free?" + end + + def valid_response?(response) + json = parse_json(response.body) + super(response) if json + end + + def results(query) + return [] unless doc = fetch_data(query) + return doc['response']['docs'] + end + + def query_url_params(query) + { + fl: '*', + q: query.text + }.merge(super) + end + end +end diff --git a/lib/geocoder/lookups/nominatim.rb b/lib/geocoder/lookups/nominatim.rb index bb37c41fa..f7e119a98 100644 --- a/lib/geocoder/lookups/nominatim.rb +++ b/lib/geocoder/lookups/nominatim.rb @@ -9,16 +9,28 @@ def name end def map_link_url(coordinates) - "http://www.openstreetmap.org/?lat=#{coordinates[0]}&lon=#{coordinates[1]}&zoom=15&layers=M" + "https://www.openstreetmap.org/?lat=#{coordinates[0]}&lon=#{coordinates[1]}&zoom=15&layers=M" end - def query_url(query) + private # --------------------------------------------------------------- + + def base_query_url(query) method = query.reverse_geocode? ? "reverse" : "search" - host = configuration[:host] || "nominatim.openstreetmap.org" - "#{protocol}://#{host}/#{method}?" + url_query_string(query) + "#{protocol}://#{configured_host}/#{method}?" end - private # --------------------------------------------------------------- + def configured_host + configuration[:host] || "nominatim.openstreetmap.org" + end + + def use_ssl? + # nominatim.openstreetmap.org redirects HTTP requests to HTTPS + if configured_host == "nominatim.openstreetmap.org" + true + else + super + end + end def results(query) return [] unless doc = fetch_data(query) diff --git a/lib/geocoder/lookups/okf.rb b/lib/geocoder/lookups/okf.rb deleted file mode 100644 index 54909bb2d..000000000 --- a/lib/geocoder/lookups/okf.rb +++ /dev/null @@ -1,44 +0,0 @@ -require 'geocoder/lookups/base' -require "geocoder/results/okf" - -module Geocoder::Lookup - class Okf < Base - - def name - "Okf" - end - - def query_url(query) - "#{protocol}://data.okf.fi/gis/1/geocode/json?" + url_query_string(query) - end - - private # --------------------------------------------------------------- - - def valid_response?(response) - json = parse_json(response.body) - status = json["status"] if json - super(response) and ['OK', 'ZERO_RESULTS'].include?(status) - end - - def results(query) - return [] unless doc = fetch_data(query) - case doc['status']; when "OK" # OK status implies >0 results - return doc['results'] - end - return [] - end - - def query_url_okf_params(query) - params = { - (query.reverse_geocode? ? :latlng : :address) => query.sanitized_text, - :sensor => "false", - :language => (query.language || configuration.language) - } - params - end - - def query_url_params(query) - query_url_okf_params(query).merge(super) - end - end -end diff --git a/lib/geocoder/lookups/opencagedata.rb b/lib/geocoder/lookups/opencagedata.rb index 230c6914d..dcd4ef641 100644 --- a/lib/geocoder/lookups/opencagedata.rb +++ b/lib/geocoder/lookups/opencagedata.rb @@ -8,15 +8,15 @@ def name "OpenCageData" end - def query_url(query) - "#{protocol}://api.opencagedata.com/geocode/v1/json?key=#{configuration.api_key}&#{url_query_string(query)}" - end - def required_api_key_parts ["key"] end - private + private # ---------------------------------------------------------------- + + def base_query_url(query) + "#{protocol}://api.opencagedata.com/geocode/v1/json?" + end def results(query) return [] unless doc = fetch_data(query) @@ -44,6 +44,7 @@ def results(query) def query_url_params(query) params = { :q => query.sanitized_text, + :key => configuration.api_key, :language => (query.language || configuration.language) }.merge(super) diff --git a/lib/geocoder/lookups/osmnames.rb b/lib/geocoder/lookups/osmnames.rb new file mode 100644 index 000000000..7a781986f --- /dev/null +++ b/lib/geocoder/lookups/osmnames.rb @@ -0,0 +1,57 @@ +require 'cgi' +require 'geocoder/lookups/base' +require 'geocoder/results/osmnames' + +module Geocoder::Lookup + class Osmnames < Base + + def name + 'OSM Names' + end + + def required_api_key_parts + configuration[:host] ? [] : ['key'] + end + + def supported_protocols + [:https] + end + + private + + def base_query_url(query) + "#{base_url(query)}/#{params_url(query)}.js?" + end + + def base_url(query) + host = configuration[:host] || 'geocoder.tilehosting.com' + "#{protocol}://#{host}" + end + + def params_url(query) + method, args = 'q', CGI.escape(query.sanitized_text) + method, args = 'r', query.coordinates.join('/') if query.reverse_geocode? + "#{country_limited(query)}#{method}/#{args}" + end + + def results(query) + return [] unless doc = fetch_data(query) + if (error = doc['message']) + raise_error(Geocoder::InvalidRequest, error) || + Geocoder.log(:warn, "OSMNames Geocoding API error: #{error}") + else + return doc['results'] + end + end + + def query_url_params(query) + { + key: configuration.api_key + }.merge(super) + end + + def country_limited(query) + "#{query.options[:country_code].downcase}/" if query.options[:country_code] && !query.reverse_geocode? + end + end +end diff --git a/lib/geocoder/lookups/ovi.rb b/lib/geocoder/lookups/ovi.rb deleted file mode 100644 index 17ef6bd0e..000000000 --- a/lib/geocoder/lookups/ovi.rb +++ /dev/null @@ -1,62 +0,0 @@ -require 'geocoder/lookups/base' -require 'geocoder/results/ovi' - -module Geocoder::Lookup - class Ovi < Base - - def name - "Ovi" - end - - def required_api_key_parts - [] - end - - def query_url(query) - "#{protocol}://lbs.ovi.com/search/6.2/#{if query.reverse_geocode? then 'reverse' end}geocode.json?" + url_query_string(query) - end - - private # --------------------------------------------------------------- - - def results(query) - return [] unless doc = fetch_data(query) - return [] unless doc['Response'] && doc['Response']['View'] - if r=doc['Response']['View'] - return [] if r.nil? || !r.is_a?(Array) || r.empty? - return r.first['Result'] - end - [] - end - - def query_url_params(query) - options = { - :gen=>1, - :app_id=>api_key, - :app_code=>api_code - } - - if query.reverse_geocode? - super.merge(options).merge( - :prox=>query.sanitized_text, - :mode=>:retrieveAddresses - ) - else - super.merge(options).merge( - :searchtext=>query.sanitized_text - ) - end - end - - def api_key - if a=configuration.api_key - return a.first if a.is_a?(Array) - end - end - - def api_code - if a=configuration.api_key - return a.last if a.is_a?(Array) - end - end - end -end diff --git a/lib/geocoder/lookups/pelias.rb b/lib/geocoder/lookups/pelias.rb index 225462550..dc48cbdb1 100644 --- a/lib/geocoder/lookups/pelias.rb +++ b/lib/geocoder/lookups/pelias.rb @@ -11,25 +11,24 @@ def endpoint configuration[:endpoint] || 'localhost' end - def query_url(query) - query_type = query.reverse_geocode? ? 'reverse' : 'search' - "#{protocol}://#{endpoint}/v1/#{query_type}?" + url_query_string(query) - end - def required_api_key_parts ['search-XXXX'] end - private + private # ---------------------------------------------------------------- + + def base_query_url(query) + query_type = query.reverse_geocode? ? 'reverse' : 'search' + "#{protocol}://#{endpoint}/v1/#{query_type}?" + end def query_url_params(query) params = { - api_key: configuration.api_key, - size: 1 + api_key: configuration.api_key }.merge(super) if query.reverse_geocode? - lat,lon = query.coordinates + lat, lon = query.coordinates params[:'point.lat'] = lat params[:'point.lon'] = lon else diff --git a/lib/geocoder/lookups/pickpoint.rb b/lib/geocoder/lookups/pickpoint.rb index 314b8d116..b5863ee99 100644 --- a/lib/geocoder/lookups/pickpoint.rb +++ b/lib/geocoder/lookups/pickpoint.rb @@ -15,12 +15,18 @@ def required_api_key_parts ["api_key"] end - def query_url(query) + private # ---------------------------------------------------------------- + + def base_query_url(query) method = query.reverse_geocode? ? "reverse" : "forward" - "#{protocol}://api.pickpoint.io/v1/#{method}?key=#{configuration.api_key}&" + url_query_string(query) + "#{protocol}://api.pickpoint.io/v1/#{method}?" end - private + def query_url_params(query) + { + key: configuration.api_key + }.merge(super) + end def results(query) return [] unless doc = fetch_data(query) diff --git a/lib/geocoder/lookups/pointpin.rb b/lib/geocoder/lookups/pointpin.rb index 356006971..0e279a12d 100644 --- a/lib/geocoder/lookups/pointpin.rb +++ b/lib/geocoder/lookups/pointpin.rb @@ -13,14 +13,18 @@ def required_api_key_parts end def query_url(query) - "#{ protocol }://geo.pointp.in/#{ api_key }/json/#{ query.sanitized_text }" + "#{protocol}://geo.pointp.in/#{configuration.api_key}/json/#{query.sanitized_text}" end - private + private # ---------------------------------------------------------------- + + def cache_key(query) + "#{protocol}://geo.pointp.in/json/#{query.sanitized_text}" + end def results(query) - # don't look up a loopback address, just return the stored result - return [] if query.loopback_ip_address? + # don't look up a loopback or private address, just return the stored result + return [] if query.internal_ip_address? doc = fetch_data(query) if doc and doc.is_a?(Hash) if !data_contains_error?(doc) @@ -38,7 +42,7 @@ def results(query) raise_error(Geocoder::Error) || Geocoder.log(:warn, "Pointpin server error") end end - + return [] end @@ -46,6 +50,7 @@ def data_contains_error?(parsed_data) parsed_data.keys.include?('error') end + # TODO: replace this hash with what's actually returned by Pointpin def reserved_result(ip) { "ip" => ip, @@ -60,9 +65,5 @@ def reserved_result(ip) "country_code" => "RD" } end - - def api_key - configuration.api_key - end end end diff --git a/lib/geocoder/lookups/postcode_anywhere_uk.rb b/lib/geocoder/lookups/postcode_anywhere_uk.rb index 017b42104..2d23ff3cf 100644 --- a/lib/geocoder/lookups/postcode_anywhere_uk.rb +++ b/lib/geocoder/lookups/postcode_anywhere_uk.rb @@ -4,7 +4,6 @@ module Geocoder::Lookup class PostcodeAnywhereUk < Base # API documentation: http://www.postcodeanywhere.co.uk/Support/WebService/Geocoding/UK/Geocode/2/ - BASE_URL_GEOCODE_V2_00 = 'services.postcodeanywhere.co.uk/Geocoding/UK/Geocode/v2.00/json.ws' DAILY_LIMIT_EXEEDED_ERROR_CODES = ['8', '17'] # api docs say these two codes are the same error INVALID_API_KEY_ERROR_CODE = '2' @@ -16,11 +15,11 @@ def required_api_key_parts %w(key) end - def query_url(query) - format('%s://%s?%s', protocol, BASE_URL_GEOCODE_V2_00, url_query_string(query)) - end + private # ---------------------------------------------------------------- - private + def base_query_url(query) + "#{protocol}://services.postcodeanywhere.co.uk/Geocoding/UK/Geocode/v2.00/json.ws?" + end def results(query) response = fetch_data(query) diff --git a/lib/geocoder/lookups/postcodes_io.rb b/lib/geocoder/lookups/postcodes_io.rb new file mode 100644 index 000000000..f2cdb4c24 --- /dev/null +++ b/lib/geocoder/lookups/postcodes_io.rb @@ -0,0 +1,31 @@ +require 'geocoder/lookups/base' +require 'geocoder/results/postcodes_io' + +module Geocoder::Lookup + class PostcodesIo < Base + def name + 'Postcodes.io' + end + + def query_url(query) + "#{protocol}://api.postcodes.io/postcodes/#{query.sanitized_text.gsub(/\s/, '')}" + end + + def supported_protocols + [:https] + end + + private # ---------------------------------------------------------------- + + def cache_key(query) + query_url(query) + end + + def results(query) + response = fetch_data(query) + return [] if response.nil? || response['status'] != 200 || response.empty? + + [response['result']] + end + end +end diff --git a/lib/geocoder/lookups/smarty_streets.rb b/lib/geocoder/lookups/smarty_streets.rb index 5d092cb94..7745a94a5 100644 --- a/lib/geocoder/lookups/smarty_streets.rb +++ b/lib/geocoder/lookups/smarty_streets.rb @@ -8,15 +8,7 @@ def name end def required_api_key_parts - %w(auti-id auth-token) - end - - def query_url(query) - if zipcode_only?(query) - "#{protocol}://us-zipcode.api.smartystreets.com/lookup?#{url_query_string(query)}" - else - "#{protocol}://us-street.api.smartystreets.com/street-address?#{url_query_string(query)}" - end + %w(auth-id auth-token) end # required by API as of 26 March 2015 @@ -26,13 +18,31 @@ def supported_protocols private # --------------------------------------------------------------- + def base_query_url(query) + if international?(query) + "#{protocol}://international-street.api.smartystreets.com/verify?" + elsif zipcode_only?(query) + "#{protocol}://us-zipcode.api.smartystreets.com/lookup?" + else + "#{protocol}://us-street.api.smartystreets.com/street-address?" + end + end + def zipcode_only?(query) !query.text.is_a?(Array) and query.to_s.strip =~ /\A\d{5}(-\d{4})?\Z/ end + def international?(query) + !query.options[:country].nil? + end + def query_url_params(query) params = {} - if zipcode_only?(query) + if international?(query) + params[:freeform] = query.sanitized_text + params[:country] = query.options[:country] + params[:geocode] = true + elsif zipcode_only?(query) params[:zipcode] = query.sanitized_text else params[:street] = query.sanitized_text @@ -47,7 +57,12 @@ def query_url_params(query) end def results(query) - fetch_data(query) || [] + doc = fetch_data(query) || [] + if doc.is_a?(Hash) and doc.key?('status') # implies there's an error + return [] + else + return doc + end end end end diff --git a/lib/geocoder/lookups/telize.rb b/lib/geocoder/lookups/telize.rb index 0609ab938..839d42e9b 100644 --- a/lib/geocoder/lookups/telize.rb +++ b/lib/geocoder/lookups/telize.rb @@ -14,9 +14,9 @@ def required_api_key_parts def query_url(query) if configuration[:host] - "#{protocol}://#{configuration[:host]}/geoip/#{query.sanitized_text}" + "#{protocol}://#{configuration[:host]}/location/#{query.sanitized_text}" else - "#{protocol}://telize-v1.p.mashape.com/geoip/#{query.sanitized_text}?mashape-key=#{api_key}" + "#{protocol}://telize-v1.p.rapidapi.com/location/#{query.sanitized_text}?rapidapi-key=#{api_key}" end end @@ -29,9 +29,13 @@ def supported_protocols private # --------------------------------------------------------------- + def cache_key(query) + query_url(query)[/(.*)\?.*/, 1] + end + def results(query) - # don't look up a loopback address, just return the stored result - return [reserved_result(query.text)] if query.loopback_ip_address? + # don't look up a loopback or private address, just return the stored result + return [reserved_result(query.text)] if query.internal_ip_address? if (doc = fetch_data(query)).nil? or doc['code'] == 401 or empty_result?(doc) [] else @@ -44,12 +48,28 @@ def empty_result?(doc) end def reserved_result(ip) - {"message" => "Input string is not a valid IP address", "code" => 401} + { + "ip" => ip, + "latitude" => 0, + "longitude" => 0, + "city" => "", + "timezone" => "", + "asn" => 0, + "region" => "", + "offset" => 0, + "organization" => "", + "country_code" => "", + "country_code3" => "", + "postal_code" => "", + "continent_code" => "", + "country" => "", + "region_code" => "" + } end def api_key configuration.api_key end - + end end diff --git a/lib/geocoder/lookups/tencent.rb b/lib/geocoder/lookups/tencent.rb new file mode 100644 index 000000000..39dcdbfbd --- /dev/null +++ b/lib/geocoder/lookups/tencent.rb @@ -0,0 +1,59 @@ +require 'geocoder/lookups/base' +require "geocoder/results/tencent" + +module Geocoder::Lookup + class Tencent < Base + + def name + "Tencent" + end + + def required_api_key_parts + ["key"] + end + + def supported_protocols + [:https] + end + + private # --------------------------------------------------------------- + + def base_query_url(query) + "#{protocol}://apis.map.qq.com/ws/geocoder/v1/?" + end + + def content_key + 'result' + end + + def results(query, reverse = false) + return [] unless doc = fetch_data(query) + case doc['status'] + when 0 + return [doc[content_key]] + when 311 + raise_error(Geocoder::InvalidApiKey, "invalid api key") || + Geocoder.log(:warn, "#{name} Geocoding API error: invalid api key.") + when 310 + raise_error(Geocoder::InvalidRequest, "invalid request.") || + Geocoder.log(:warn, "#{name} Geocoding API error: invalid request, invalid parameters.") + when 306 + raise_error(Geocoder::InvalidRequest, "invalid request.") || + Geocoder.log(:warn, "#{name} Geocoding API error: invalid request, check response for more info.") + when 110 + raise_error(Geocoder::RequestDenied, "request denied.") || + Geocoder.log(:warn, "#{name} Geocoding API error: request source is not authorized.") + end + return [] + end + + def query_url_params(query) + { + (query.reverse_geocode? ? :location : :address) => query.sanitized_text, + :key => configuration.api_key, + :output => "json" + }.merge(super) + end + + end +end diff --git a/lib/geocoder/lookups/uk_ordnance_survey_names.rb b/lib/geocoder/lookups/uk_ordnance_survey_names.rb new file mode 100644 index 000000000..b89ecd6d1 --- /dev/null +++ b/lib/geocoder/lookups/uk_ordnance_survey_names.rb @@ -0,0 +1,59 @@ +require 'geocoder/lookups/base' +require 'geocoder/results/uk_ordnance_survey_names' + +module Geocoder::Lookup + class UkOrdnanceSurveyNames < Base + + def name + 'Ordance Survey Names' + end + + def supported_protocols + [:https] + end + + def base_query_url(query) + "#{protocol}://api.ordnancesurvey.co.uk/opennames/v1/find?" + end + + def required_api_key_parts + ["key"] + end + + def query_url(query) + base_query_url(query) + url_query_string(query) + end + + private # ------------------------------------------------------------- + + def results(query) + return [] unless doc = fetch_data(query) + return [] if doc['header']['totalresults'].zero? + return doc['results'].map { |r| r['GAZETTEER_ENTRY'] } + end + + def query_url_params(query) + { + query: query.sanitized_text, + key: configuration.api_key, + fq: filter + }.merge(super) + end + + def local_types + %w[ + City + Hamlet + Other_Settlement + Town + Village + Postcode + ] + end + + def filter + local_types.map { |t| "local_type:#{t}" }.join(' ') + end + + end +end diff --git a/lib/geocoder/lookups/yandex.rb b/lib/geocoder/lookups/yandex.rb index 2d9ffd3b9..3d3d8e26e 100644 --- a/lib/geocoder/lookups/yandex.rb +++ b/lib/geocoder/lookups/yandex.rb @@ -12,16 +12,16 @@ def map_link_url(coordinates) "http://maps.yandex.ru/?ll=#{coordinates.reverse.join(',')}" end - def query_url(query) - "#{protocol}://geocode-maps.yandex.ru/1.x/?" + url_query_string(query) - end - def supported_protocols [:https] end private # --------------------------------------------------------------- + def base_query_url(query) + "#{protocol}://geocode-maps.yandex.ru/1.x/?" + end + def results(query) return [] unless doc = fetch_data(query) if err = doc['error'] @@ -33,8 +33,7 @@ def results(query) return [] end if doc = doc['response']['GeoObjectCollection'] - meta = doc['metaDataProperty']['GeocoderResponseMetaData'] - return meta['found'].to_i > 0 ? doc['featureMember'] : [] + return doc['featureMember'].to_a else Geocoder.log(:warn, "Yandex Geocoding API error: unexpected response format.") return [] @@ -50,8 +49,8 @@ def query_url_params(query) params = { :geocode => q, :format => "json", - :plng => "#{query.language || configuration.language}", # supports ru, uk, be - :key => configuration.api_key + :lang => "#{query.language || configuration.language}", # supports ru, uk, be, default -> ru + :apikey => configuration.api_key } unless (bounds = query.options[:bounds]).nil? params[:bbox] = bounds.map{ |point| "%f,%f" % point }.join('~') diff --git a/lib/geocoder/query.rb b/lib/geocoder/query.rb index 61710ef92..223cb3167 100644 --- a/lib/geocoder/query.rb +++ b/lib/geocoder/query.rb @@ -66,6 +66,13 @@ def ip_address? IpAddress.new(text).valid? rescue false end + ## + # Is the Query text a loopback or private IP address? + # + def internal_ip_address? + ip_address? && IpAddress.new(text).internal? + end + ## # Is the Query text a loopback IP address? # @@ -73,6 +80,13 @@ def loopback_ip_address? ip_address? && IpAddress.new(text).loopback? end + ## + # Is the Query text a private IP address? + # + def private_ip_address? + ip_address? && IpAddress.new(text).private? + end + ## # Does the given string look like latitude/longitude coordinates? # diff --git a/lib/geocoder/railtie.rb b/lib/geocoder/railtie.rb index ec1113170..809d6f236 100644 --- a/lib/geocoder/railtie.rb +++ b/lib/geocoder/railtie.rb @@ -4,7 +4,7 @@ module Geocoder if defined? Rails::Railtie require 'rails' class Railtie < Rails::Railtie - initializer 'geocoder.insert_into_active_record' do + initializer 'geocoder.insert_into_active_record', before: :load_config_initializers do ActiveSupport.on_load :active_record do Geocoder::Railtie.insert end diff --git a/lib/geocoder/request.rb b/lib/geocoder/request.rb index 5e2eb6c99..0180cf958 100644 --- a/lib/geocoder/request.rb +++ b/lib/geocoder/request.rb @@ -81,7 +81,18 @@ def geocoder_reject_trusted_ip_addresses(ip_addresses) end def geocoder_remove_port_from_addresses(ip_addresses) - ip_addresses.map { |ip| ip.split(':').first } + ip_addresses.map do |ip| + # IPv4 + if ip.count('.') > 0 + ip.split(':').first + # IPv6 bracket notation + elsif match = ip.match(/\[(\S+)\]/) + match.captures.first + # IPv6 bare notation + else + ip + end + end end def geocoder_reject_non_ipv4_addresses(ip_addresses) diff --git a/lib/geocoder/results/baidu.rb b/lib/geocoder/results/baidu.rb index 62fbc6f1d..c6fd36ea8 100644 --- a/lib/geocoder/results/baidu.rb +++ b/lib/geocoder/results/baidu.rb @@ -7,38 +7,34 @@ def coordinates ['lat', 'lng'].map{ |i| @data['location'][i] } end - def address - @data['formatted_address'] - end - - def state - province - end - def province - @data['addressComponent']['province'] + @data['addressComponent'] and @data['addressComponent']['province'] or "" end + alias_method :state, :province + def city - @data['addressComponent']['city'] + @data['addressComponent'] and @data['addressComponent']['city'] or "" end def district - @data['addressComponent']['district'] + @data['addressComponent'] and @data['addressComponent']['district'] or "" end def street - @data['addressComponent']['street'] + @data['addressComponent'] and @data['addressComponent']['street'] or "" end def street_number - @data['addressComponent']['street_number'] + @data['addressComponent'] and @data['addressComponent']['street_number'] end def formatted_address - @data['formatted_address'] + @data['formatted_address'] or "" end + alias_method :address, :formatted_address + def address_components @data['addressComponent'] end diff --git a/lib/geocoder/results/ban_data_gouv_fr.rb b/lib/geocoder/results/ban_data_gouv_fr.rb index 0b936b043..2ca2b6feb 100644 --- a/lib/geocoder/results/ban_data_gouv_fr.rb +++ b/lib/geocoder/results/ban_data_gouv_fr.rb @@ -7,7 +7,7 @@ class BanDataGouvFr < Base #### BASE METHODS #### def self.response_attributes - %w[limit attribution version licence type features] + %w[limit attribution version licence type features center] end response_attributes.each do |a| diff --git a/lib/geocoder/results/base.rb b/lib/geocoder/results/base.rb index a798ced68..7fe179c92 100644 --- a/lib/geocoder/results/base.rb +++ b/lib/geocoder/results/base.rb @@ -20,8 +20,20 @@ def initialize(data) ## # A string in the given format. # + # This default implementation dumbly follows the United States address + # format and will return incorrect results for most countries. Some APIs + # return properly formatted addresses and those should be funneled + # through this method. + # def address(format = :full) - fail + if state_code.to_s != "" + s = ", #{state_code}" + elsif state.to_s != "" + s = ", #{state}" + else + s = "" + end + "#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, '') end ## diff --git a/lib/geocoder/results/bing.rb b/lib/geocoder/results/bing.rb index 77b5eee34..ea184e397 100644 --- a/lib/geocoder/results/bing.rb +++ b/lib/geocoder/results/bing.rb @@ -24,7 +24,7 @@ def country alias_method :country_code, :country def postal_code - @data['address']['postalCode'] + @data['address']['postalCode'].to_s end def coordinates diff --git a/lib/geocoder/results/db_ip_com.rb b/lib/geocoder/results/db_ip_com.rb index 2328bd0dd..f5291bf2d 100644 --- a/lib/geocoder/results/db_ip_com.rb +++ b/lib/geocoder/results/db_ip_com.rb @@ -7,11 +7,6 @@ def coordinates ['latitude', 'longitude'].map{ |coordinate_name| @data[coordinate_name] } end - def address(format = :full) - s = state_code.to_s == "" ? "" : ", #{state_code}" - "#{city}#{s} #{zip_code}, #{country_name}".sub(/^[ ,]*/, "") - end - def city @data['city'] end diff --git a/lib/geocoder/results/freegeoip.rb b/lib/geocoder/results/freegeoip.rb index d990e5647..0ddde2f76 100644 --- a/lib/geocoder/results/freegeoip.rb +++ b/lib/geocoder/results/freegeoip.rb @@ -3,11 +3,6 @@ module Geocoder::Result class Freegeoip < Base - def address(format = :full) - s = state_code.to_s == "" ? "" : ", #{state_code}" - "#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, "") - end - def city @data['city'] end diff --git a/lib/geocoder/results/geocoder_ca.rb b/lib/geocoder/results/geocoder_ca.rb index 4edb80a83..c16ec5a33 100644 --- a/lib/geocoder/results/geocoder_ca.rb +++ b/lib/geocoder/results/geocoder_ca.rb @@ -16,17 +16,17 @@ def street_address end def city - @data['city'] + @data['city'] or (@data['standard'] and @data['standard']['city']) or "" end def state - @data['prov'] + @data['prov'] or (@data['standard'] and @data['standard']['prov']) or "" end alias_method :state_code, :state def postal_code - @data['postal'] + @data['postal'] or (@data['standard'] and @data['standard']['postal']) or "" end def country diff --git a/lib/geocoder/results/geocoder_us.rb b/lib/geocoder/results/geocoder_us.rb deleted file mode 100644 index ca20ad418..000000000 --- a/lib/geocoder/results/geocoder_us.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'geocoder/results/base' - -module Geocoder::Result - class GeocoderUs < Base - def coordinates - [@data[0].to_f, @data[1].to_f] - end - - def address(format = :full) - "#{street_address}, #{city}, #{state} #{postal_code}, #{country}".sub(/^[ ,]*/, "") - end - - def street_address - @data[2] - end - - def city - @data[3] - end - - def state - @data[4] - end - - alias_method :state_code, :state - - def postal_code - @data[5] - end - - def country - 'United States' - end - - def country_code - 'US' - end - end -end diff --git a/lib/geocoder/results/geoip2.rb b/lib/geocoder/results/geoip2.rb index 5e8b00884..1381747fc 100644 --- a/lib/geocoder/results/geoip2.rb +++ b/lib/geocoder/results/geoip2.rb @@ -3,10 +3,6 @@ module Geocoder module Result class Geoip2 < Base - def address(format = :full) - s = state.to_s == '' ? '' : ", #{state_code}" - "#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, '') - end def coordinates %w[latitude longitude].map do |l| @@ -62,12 +58,12 @@ def language @language ||= default_language end - private - def data @data.to_hash end + private + def default_language @default_language = Geocoder.config[:language].to_s end diff --git a/lib/geocoder/results/geoportail_lu.rb b/lib/geocoder/results/geoportail_lu.rb index eeccb34b6..48521ea39 100644 --- a/lib/geocoder/results/geoportail_lu.rb +++ b/lib/geocoder/results/geoportail_lu.rb @@ -59,11 +59,13 @@ def detailled_address private def geolocalized? - try_to_extract('coordinates', geomlonlat).present? + !!try_to_extract('coordinates', geomlonlat) end - def try_to_extract(key, nullable_hash) - nullable_hash.try(:[], key) + def try_to_extract(key, hash) + if hash.is_a?(Hash) and hash.include?(key) + hash[key] + end end end end diff --git a/lib/geocoder/results/google.rb b/lib/geocoder/results/google.rb index 804e4ea58..e1215ff41 100644 --- a/lib/geocoder/results/google.rb +++ b/lib/geocoder/results/google.rb @@ -120,19 +120,30 @@ def geometry def precision geometry['location_type'] if geometry end - + def partial_match @data['partial_match'] end - + def place_id @data['place_id'] - end + end def viewport viewport = geometry['viewport'] || fail - south, west = %w(lat lng).map { |c| viewport['southwest'][c] } - north, east = %w(lat lng).map { |c| viewport['northeast'][c] } + bounding_box_from viewport + end + + def bounds + bounding_box_from geometry['bounds'] + end + + private + + def bounding_box_from(box) + return nil unless box + south, west = %w(lat lng).map { |c| box['southwest'][c] } + north, east = %w(lat lng).map { |c| box['northeast'][c] } [south, west, north, east] end end diff --git a/lib/geocoder/results/here.rb b/lib/geocoder/results/here.rb index 12f3ab807..636c6c194 100644 --- a/lib/geocoder/results/here.rb +++ b/lib/geocoder/results/here.rb @@ -27,7 +27,10 @@ def street_number end def state - address_data['County'] + fail unless d = address_data['AdditionalData'] + if v = d.find{|ad| ad['key']=='StateName'} + return v['value'] + end end def province diff --git a/lib/geocoder/results/ip2location.rb b/lib/geocoder/results/ip2location.rb new file mode 100644 index 000000000..57d0c1785 --- /dev/null +++ b/lib/geocoder/results/ip2location.rb @@ -0,0 +1,22 @@ +require 'geocoder/results/base' + +module Geocoder::Result + class Ip2location < Base + + def address(format = :full) + "#{city_name} #{zip_code}, #{country_name}".sub(/^[ ,]*/, '') + end + + def self.response_attributes + %w[country_code country_name region_name city_name latitude longitude + zip_code time_zone isp domain net_speed idd_code area_code usage_type + weather_station_code weather_station_name mcc mnc mobile_brand elevation] + end + + response_attributes.each do |attr| + define_method attr do + @data[attr] || "" + end + end + end +end diff --git a/lib/geocoder/results/ipdata_co.rb b/lib/geocoder/results/ipdata_co.rb new file mode 100644 index 000000000..b6d2362c1 --- /dev/null +++ b/lib/geocoder/results/ipdata_co.rb @@ -0,0 +1,40 @@ +require 'geocoder/results/base' + +module Geocoder::Result + class IpdataCo < Base + + def city + @data['city'] + end + + def state + @data['region'] + end + + def state_code + @data['region_code'] + end + + def country + @data['country_name'] + end + + def country_code + @data['country_code'] + end + + def postal_code + @data['postal'] + end + + def self.response_attributes + %w[ip asn organisation currency currency_symbol calling_code flag time_zone is_eu] + end + + response_attributes.each do |a| + define_method a do + @data[a] + end + end + end +end diff --git a/lib/geocoder/results/ipgeolocation.rb b/lib/geocoder/results/ipgeolocation.rb new file mode 100644 index 000000000..15dd05b13 --- /dev/null +++ b/lib/geocoder/results/ipgeolocation.rb @@ -0,0 +1,59 @@ +require 'geocoder/results/base' + +module Geocoder::Result + class Ipgeolocation < Base + + def coordinates + [@data['latitude'].to_f, @data['longitude'].to_f] + end + + def address(format = :full) + "#{city}, #{state} #{postal_code}, #{country_name}".sub(/^[ ,]*/, "") + end + + def state + @data['state_prov'] + end + + def state_code + @data['state_prov'] + end + + def country + @data['country_name'] + end + + def country_code + @data['country_code2'] + end + + def postal_code + @data['zipcode'] + end + + def self.response_attributes + [ + ['ip', ''], + ['hostname', ''], + ['continent_code', ''], + ['continent_name', ''], + ['country_code2', ''], + ['country_code3', ''], + ['country_name', ''], + ['country_capital',''], + ['district',''], + ['state_prov',''], + ['city', ''], + ['zipcode', ''], + ['time_zone', {}], + ['currency', {}] + ] + end + + response_attributes.each do |attr, default| + define_method attr do + @data[attr] || default + end + end + end +end diff --git a/lib/geocoder/results/ipregistry.rb b/lib/geocoder/results/ipregistry.rb new file mode 100644 index 000000000..33e3193d1 --- /dev/null +++ b/lib/geocoder/results/ipregistry.rb @@ -0,0 +1,308 @@ +require 'geocoder/results/base' + +module Geocoder::Result + class Ipregistry < Base + + def initialize(data) + super + + @data = flatten_hash(data) + end + + def flatten_hash(hash) + hash.each_with_object({}) do |(k, v), h| + if v.is_a? Hash + flatten_hash(v).map do |h_k, h_v| + h["#{k}_#{h_k}".to_s] = h_v + end + else + h[k] = v + end + end + end + + private :flatten_hash + + def city + @data['location_city'] + end + + def country + @data['location_country_name'] + end + + def country_code + @data['location_country_code'] + end + + def latitude + @data['location_latitude'] + end + + def longitude + @data['location_longitude'] + end + + def postal_code + @data['location_postal'] + end + + def state + @data['location_region_name'] + end + + def state_code + @data['location_region_code'] + end + + # methods for fields specific to Ipregistry + + def ip + @data["ip"] + end + + def type + @data["type"] + end + + def hostname + @data["hostname"] + end + + def carrier_name + @data["carrier_name"] + end + + def carrier_mcc + @data["carrier_mcc"] + end + + def carrier_mnc + @data["carrier_mnc"] + end + + def connection_asn + @data["connection_asn"] + end + + def connection_domain + @data["connection_domain"] + end + + def connection_organization + @data["connection_organization"] + end + + def connection_type + @data["connection_type"] + end + + def currency_code + @data["currency_code"] + end + + def currency_name + @data["currency_name"] + end + + def currency_plural + @data["currency_plural"] + end + + def currency_symbol + @data["currency_symbol"] + end + + def currency_symbol_native + @data["currency_symbol_native"] + end + + def currency_format_negative_prefix + @data["currency_format_negative_prefix"] + end + + def currency_format_negative_suffix + @data["currency_format_negative_suffix"] + end + + def currency_format_positive_prefix + @data["currency_format_positive_prefix"] + end + + def currency_format_positive_suffix + @data["currency_format_positive_suffix"] + end + + def location_continent_code + @data["location_continent_code"] + end + + def location_continent_name + @data["location_continent_name"] + end + + def location_country_area + @data["location_country_area"] + end + + def location_country_borders + @data["location_country_borders"] + end + + def location_country_calling_code + @data["location_country_calling_code"] + end + + def location_country_capital + @data["location_country_capital"] + end + + def location_country_code + @data["location_country_code"] + end + + def location_country_name + @data["location_country_name"] + end + + def location_country_population + @data["location_country_population"] + end + + def location_country_population_density + @data["location_country_population_density"] + end + + def location_country_flag_emoji + @data["location_country_flag_emoji"] + end + + def location_country_flag_emoji_unicode + @data["location_country_flag_emoji_unicode"] + end + + def location_country_flag_emojitwo + @data["location_country_flag_emojitwo"] + end + + def location_country_flag_noto + @data["location_country_flag_noto"] + end + + def location_country_flag_twemoji + @data["location_country_flag_twemoji"] + end + + def location_country_flag_wikimedia + @data["location_country_flag_wikimedia"] + end + + def location_country_languages + @data["location_country_languages"] + end + + def location_country_tld + @data["location_country_tld"] + end + + def location_region_code + @data["location_region_code"] + end + + def location_region_name + @data["location_region_name"] + end + + def location_city + @data["location_city"] + end + + def location_postal + @data["location_postal"] + end + + def location_latitude + @data["location_latitude"] + end + + def location_longitude + @data["location_longitude"] + end + + def location_language_code + @data["location_language_code"] + end + + def location_language_name + @data["location_language_name"] + end + + def location_language_native + @data["location_language_native"] + end + + def location_in_eu + @data["location_in_eu"] + end + + def security_is_bogon + @data["security_is_bogon"] + end + + def security_is_cloud_provider + @data["security_is_cloud_provider"] + end + + def security_is_tor + @data["security_is_tor"] + end + + def security_is_tor_exit + @data["security_is_tor_exit"] + end + + def security_is_proxy + @data["security_is_proxy"] + end + + def security_is_anonymous + @data["security_is_anonymous"] + end + + def security_is_abuser + @data["security_is_abuser"] + end + + def security_is_attacker + @data["security_is_attacker"] + end + + def security_is_threat + @data["security_is_threat"] + end + + def time_zone_id + @data["time_zone_id"] + end + + def time_zone_abbreviation + @data["time_zone_abbreviation"] + end + + def time_zone_current_time + @data["time_zone_current_time"] + end + + def time_zone_name + @data["time_zone_name"] + end + + def time_zone_offset + @data["time_zone_offset"] + end + + def time_zone_in_daylight_saving + @data["time_zone_in_daylight_saving"] + end + end +end diff --git a/lib/geocoder/results/ipstack.rb b/lib/geocoder/results/ipstack.rb new file mode 100644 index 000000000..af1099fb8 --- /dev/null +++ b/lib/geocoder/results/ipstack.rb @@ -0,0 +1,60 @@ +require 'geocoder/results/base' + +module Geocoder::Result + class Ipstack < Base + + def address(format = :full) + s = region_code.empty? ? "" : ", #{region_code}" + "#{city}#{s} #{zip}, #{country_name}".sub(/^[ ,]*/, "") + end + + def state + @data['region_name'] + end + + def state_code + @data['region_code'] + end + + def country + @data['country_name'] + end + + def postal_code + @data['zip'] || @data['zipcode'] || @data['zip_code'] + end + + def self.response_attributes + [ + ['ip', ''], + ['hostname', ''], + ['continent_code', ''], + ['continent_name', ''], + ['country_code', ''], + ['country_name', ''], + ['region_code', ''], + ['region_name', ''], + ['city', ''], + ['zip', ''], + ['latitude', 0], + ['longitude', 0], + ['location', {}], + ['time_zone', {}], + ['currency', {}], + ['connection', {}], + ['security', {}], + ] + end + + response_attributes.each do |attr, default| + define_method attr do + @data[attr] || default + end + end + + def metro_code + Geocoder.log(:warn, "Ipstack does not implement `metro_code` in api results. Please discontinue use.") + 0 # no longer implemented by ipstack + end + end +end diff --git a/lib/geocoder/results/mapzen.rb b/lib/geocoder/results/mapzen.rb deleted file mode 100644 index 125f4da86..000000000 --- a/lib/geocoder/results/mapzen.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'geocoder/results/pelias' - -module Geocoder::Result - class Mapzen < Pelias; end -end diff --git a/lib/geocoder/results/maxmind.rb b/lib/geocoder/results/maxmind.rb index 6682bfc64..a0744f8a8 100644 --- a/lib/geocoder/results/maxmind.rb +++ b/lib/geocoder/results/maxmind.rb @@ -87,11 +87,6 @@ def coordinates [data_hash[:latitude].to_f, data_hash[:longitude].to_f] end - def address(format = :full) - s = state_code.to_s == "" ? "" : ", #{state_code}" - "#{city}#{s} #{postal_code}, #{country_code}".sub(/^[ ,]*/, "") - end - def city data_hash[:city_name] end diff --git a/lib/geocoder/results/maxmind_local.rb b/lib/geocoder/results/maxmind_local.rb index 81b545ab4..4f8929e96 100644 --- a/lib/geocoder/results/maxmind_local.rb +++ b/lib/geocoder/results/maxmind_local.rb @@ -3,11 +3,6 @@ module Geocoder::Result class MaxmindLocal < Base - def address(format = :full) - s = state.to_s == "" ? "" : ", #{state}" - "#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, "") - end - def coordinates [@data[:latitude], @data[:longitude]] end diff --git a/lib/geocoder/results/nationaal_georegister_nl.rb b/lib/geocoder/results/nationaal_georegister_nl.rb new file mode 100644 index 000000000..aa0def236 --- /dev/null +++ b/lib/geocoder/results/nationaal_georegister_nl.rb @@ -0,0 +1,62 @@ +require 'geocoder/results/base' + +module Geocoder::Result + class NationaalGeoregisterNl < Base + + def response_attributes + @data + end + + def coordinates + @data['centroide_ll'][6..-2].split(' ').map(&:to_f) + end + + def formatted_address + @data['weergavenaam'] + end + + alias_method :address, :formatted_address + + def province + @data['provincienaam'] + end + + alias_method :state, :province + + def city + @data['woonplaatsnaam'] + end + + def district + @data['gemeentenaam'] + end + + def street + @data['straatnaam'] + end + + def street_number + @data['huis_nlt'] + end + + def address_components + @data + end + + def state_code + @data['provinciecode'] + end + + def postal_code + @data['postcode'] + end + + def country + "Netherlands" + end + + def country_code + "NL" + end + end +end diff --git a/lib/geocoder/results/okf.rb b/lib/geocoder/results/okf.rb deleted file mode 100644 index 973922591..000000000 --- a/lib/geocoder/results/okf.rb +++ /dev/null @@ -1,106 +0,0 @@ -require 'geocoder/results/base' - -module Geocoder::Result - class Okf < Base - - def coordinates - ['lat', 'lng'].map{ |i| geometry['location'][i] } - end - - def address(format = :full) - formatted_address - end - - def city - fields = [:locality, :sublocality, - :administrative_area_level_3, - :administrative_area_level_2] - fields.each do |f| - if entity = address_components_of_type(f).first - return entity['long_name'] - end - end - return nil # no appropriate components found - end - - def state - "" - end - - def sub_state - "" - end - - def state_code - "" - end - - def country - if country = address_components_of_type(:country).first - country['long_name'] - end - end - - def country_code - if country = address_components_of_type(:country).first - country['short_name'] - end - end - - def postal_code - if postal = address_components_of_type(:postal_code).first - postal['long_name'] - end - end - - def route - if route = address_components_of_type(:route).first - route['long_name'] - end - end - - def street_number - if street_number = address_components_of_type(:street_number).first - street_number['long_name'] - end - end - - def street_address - [route, street_number].compact.join(' ') - end - - def types - @data['types'] - end - - def formatted_address - @data['formatted_address'] - end - - def address_components - @data['address_components'] - end - - ## - # Get address components of a given type. Valid types are defined in - # Google's Geocoding API documentation and include (among others): - # - # :street_number - # :locality - # :neighborhood - # :route - # :postal_code - # - def address_components_of_type(type) - address_components.select{ |c| c['types'].include?(type.to_s) } - end - - def geometry - @data['geometry'] - end - - def precision - geometry['location_type'] if geometry - end - end -end diff --git a/lib/geocoder/results/osmnames.rb b/lib/geocoder/results/osmnames.rb new file mode 100644 index 000000000..5954e75cb --- /dev/null +++ b/lib/geocoder/results/osmnames.rb @@ -0,0 +1,56 @@ +require 'geocoder/results/base' + +module Geocoder::Result + class Osmnames < Base + def address + @data['display_name'] + end + + def coordinates + [@data['lat'].to_f, @data['lon'].to_f] + end + + def viewport + west, south, east, north = @data['boundingbox'].map(&:to_f) + [south, west, north, east] + end + + def state + @data['state'] + end + alias_method :state_code, :state + + def place_class + @data['class'] + end + + def place_type + @data['type'] + end + + def postal_code + '' + end + + def country_code + @data['country_code'] + end + + def country + @data['country'] + end + + def self.response_attributes + %w[house_number street city name osm_id osm_type boundingbox place_rank + importance county rank name_suffix] + end + + response_attributes.each do |a| + unless method_defined?(a) + define_method a do + @data[a] + end + end + end + end +end diff --git a/lib/geocoder/results/ovi.rb b/lib/geocoder/results/ovi.rb deleted file mode 100644 index 552e2289c..000000000 --- a/lib/geocoder/results/ovi.rb +++ /dev/null @@ -1,71 +0,0 @@ -require 'geocoder/results/base' - -module Geocoder::Result - class Ovi < Base - - ## - # A string in the given format. - # - def address(format = :full) - address_data['Label'] - end - - ## - # A two-element array: [lat, lon]. - # - def coordinates - fail unless d = @data['Location']['DisplayPosition'] - [d['Latitude'].to_f, d['Longitude'].to_f] - end - - def state - address_data['County'] - end - - def province - address_data['County'] - end - - def postal_code - address_data['PostalCode'] - end - - def city - address_data['City'] - end - - def state_code - address_data['State'] - end - - def province_code - address_data['State'] - end - - def country - fail unless d = address_data['AdditionalData'] - if v = d.find{|ad| ad['key']=='CountryName'} - return v['value'] - end - end - - def country_code - address_data['Country'] - end - - def viewport - map_view = data['Location']['MapView'] || fail - south = map_view['BottomRight']['Latitude'] - west = map_view['TopLeft']['Longitude'] - north = map_view['TopLeft']['Latitude'] - east = map_view['BottomRight']['Longitude'] - [south, west, north, east] - end - - private # ---------------------------------------------------------------- - - def address_data - @data['Location']['Address'] || fail - end - end -end diff --git a/lib/geocoder/results/postcodes_io.rb b/lib/geocoder/results/postcodes_io.rb new file mode 100644 index 000000000..caaa042ec --- /dev/null +++ b/lib/geocoder/results/postcodes_io.rb @@ -0,0 +1,40 @@ +require 'geocoder/results/base' + +module Geocoder::Result + class PostcodesIo < Base + + def coordinates + [@data['latitude'].to_f, @data['longitude'].to_f] + end + + def quality + @data['quality'] + end + + def postal_code + @data['postcode'] + end + alias address postal_code + + def city + @data['admin_ward'] + end + + def county + @data['admin_county'] + end + alias state county + + def state_code + @data['codes']['admin_county'] + end + + def country + 'United Kingdom' + end + + def country_code + 'UK' + end + end +end diff --git a/lib/geocoder/results/smarty_streets.rb b/lib/geocoder/results/smarty_streets.rb index b4850677f..62ce8acc5 100644 --- a/lib/geocoder/results/smarty_streets.rb +++ b/lib/geocoder/results/smarty_streets.rb @@ -15,51 +15,77 @@ def coordinates end def address - [ - delivery_line_1, - delivery_line_2, - last_line - ].select{ |i| i.to_s != "" }.join(" ") + parts = + if international_endpoint? + (1..12).map { |i| @data["address#{i}"] } + else + [ + delivery_line_1, + delivery_line_2, + last_line + ] + end + parts.select{ |i| i.to_s != "" }.join(" ") end def state - zipcode_endpoint? ? - city_states.first['state'] : + if international_endpoint? + components['administrative_area'] + elsif zipcode_endpoint? + city_states.first['state'] + else components['state_abbreviation'] + end end def state_code - zipcode_endpoint? ? - city_states.first['state_abbreviation'] : + if international_endpoint? + components['administrative_area'] + elsif zipcode_endpoint? + city_states.first['state_abbreviation'] + else components['state_abbreviation'] + end end def country - # SmartyStreets returns results for USA only - "United States" + international_endpoint? ? + components['country_iso_3'] : + "United States" end def country_code - # SmartyStreets returns results for USA only - "US" + international_endpoint? ? + components['country_iso_3'] : + "US" end ## Extra methods not in base.rb ------------------------ def street - components['street_name'] + international_endpoint? ? + components['thoroughfare_name'] : + components['street_name'] end def city - zipcode_endpoint? ? - city_states.first['city'] : + if international_endpoint? + components['locality'] + elsif zipcode_endpoint? + city_states.first['city'] + else components['city_name'] + end end def zipcode - zipcode_endpoint? ? - zipcodes.first['zipcode'] : + if international_endpoint? + components['postal_code'] + elsif zipcode_endpoint? + zipcodes.first['zipcode'] + else components['zipcode'] + end end alias_method :postal_code, :zipcode @@ -78,6 +104,10 @@ def zipcode_endpoint? zipcodes.any? end + def international_endpoint? + !@data['address1'].nil? + end + [ :delivery_line_1, :delivery_line_2, diff --git a/lib/geocoder/results/telize.rb b/lib/geocoder/results/telize.rb index ee8880b76..d853faaf1 100644 --- a/lib/geocoder/results/telize.rb +++ b/lib/geocoder/results/telize.rb @@ -3,11 +3,6 @@ module Geocoder::Result class Telize < Base - def address(format = :full) - s = state_code.to_s == "" ? "" : ", #{state_code}" - "#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, "") - end - def city @data['city'] end diff --git a/lib/geocoder/results/tencent.rb b/lib/geocoder/results/tencent.rb new file mode 100644 index 000000000..c8bb23130 --- /dev/null +++ b/lib/geocoder/results/tencent.rb @@ -0,0 +1,72 @@ +require 'geocoder/results/base' + +module Geocoder::Result + class Tencent < Base + + def coordinates + ['lat', 'lng'].map{ |i| @data['location'][i] } + end + + def address + "#{province}#{city}#{district}#{street}#{street_number}" + + #@data['title'] or @data['address'] + end + + # NOTE: The Tencent reverse geocoding API has the field named + # 'address_component' compared to 'address_components' in the + # regular geocoding API. + def province + @data['address_components'] and (@data['address_components']['province']) or + (@data['address_component'] and @data['address_component']['province']) or + "" + end + + alias_method :state, :province + + def city + @data['address_components'] and (@data['address_components']['city']) or + (@data['address_component'] and @data['address_component']['city']) or + "" + end + + def district + @data['address_components'] and (@data['address_components']['district']) or + (@data['address_component'] and @data['address_component']['district']) or + "" + end + + def street + @data['address_components'] and (@data['address_components']['street']) or + (@data['address_component'] and @data['address_component']['street']) or + "" + end + + def street_number + @data['address_components'] and (@data['address_components']['street_number']) or + (@data['address_component'] and @data['address_component']['street_number']) or + "" + end + + def address_components + @data['address_components'] or @data['address_component'] + end + + def state_code + "" + end + + def postal_code + "" + end + + def country + "China" + end + + def country_code + "CN" + end + + end +end \ No newline at end of file diff --git a/lib/geocoder/results/test.rb b/lib/geocoder/results/test.rb index 61d422ce1..06dfca10c 100644 --- a/lib/geocoder/results/test.rb +++ b/lib/geocoder/results/test.rb @@ -15,7 +15,7 @@ def self.add_result_attribute(attr) end end - %w[latitude longitude neighborhood city state state_code sub_state + %w[coordinates neighborhood city state state_code sub_state sub_state_code province province_code postal_code country country_code address street_address street_number route geometry].each do |attr| add_result_attribute(attr) diff --git a/lib/geocoder/results/uk_ordnance_survey_names.rb b/lib/geocoder/results/uk_ordnance_survey_names.rb new file mode 100644 index 000000000..c09d357bd --- /dev/null +++ b/lib/geocoder/results/uk_ordnance_survey_names.rb @@ -0,0 +1,59 @@ +require 'geocoder/results/base' +require 'easting_northing' + +module Geocoder::Result + class UkOrdnanceSurveyNames < Base + + def coordinates + @coordinates ||= Geocoder::EastingNorthing.new( + easting: data['GEOMETRY_X'], + northing: data['GEOMETRY_Y'], + ).lat_lng + end + + def city + is_postcode? ? data['DISTRICT_BOROUGH'] : data['NAME1'] + end + + def county + data['COUNTY_UNITARY'] + end + alias state county + + def county_code + code_from_uri data['COUNTY_UNITARY_URI'] + end + alias state_code county_code + + def province + data['REGION'] + end + + def province_code + code_from_uri data['REGION_URI'] + end + + def postal_code + is_postcode? ? data['NAME1'] : '' + end + + def country + 'United Kingdom' + end + + def country_code + 'UK' + end + + private + + def is_postcode? + data['LOCAL_TYPE'] == 'Postcode' + end + + def code_from_uri(uri) + return '' if uri.nil? + uri.split('/').last + end + end +end diff --git a/lib/geocoder/results/yandex.rb b/lib/geocoder/results/yandex.rb index 524353309..eced22793 100644 --- a/lib/geocoder/results/yandex.rb +++ b/lib/geocoder/results/yandex.rb @@ -2,78 +2,223 @@ module Geocoder::Result class Yandex < Base + # Yandex result has difficult tree structure, + # and presence of some nodes depends on exact search case. + + # Also Yandex lacks documentation about it. + # See https://tech.yandex.com/maps/doc/geocoder/desc/concepts/response_structure-docpage/ + + # Ultimatly, we need to find Locality and/or Thoroughfare data. + + # It may resides on the top (ADDRESS_DETAILS) level. + # example: 'Baltic Sea' + # "AddressDetails": { + # "Locality": { + # "Premise": { + # "PremiseName": "Baltic Sea" + # } + # } + # } + + ADDRESS_DETAILS = %w[ + GeoObject metaDataProperty GeocoderMetaData + AddressDetails + ].freeze + + # On COUNTRY_LEVEL. + # example: 'Potomak' + # "AddressDetails": { + # "Country": { + # "AddressLine": "reka Potomak", + # "CountryNameCode": "US", + # "CountryName": "United States of America", + # "Locality": { + # "Premise": { + # "PremiseName": "reka Potomak" + # } + # } + # } + # } + + COUNTRY_LEVEL = %w[ + GeoObject metaDataProperty GeocoderMetaData + AddressDetails Country + ].freeze + + # On ADMIN_LEVEL (usually state or city) + # example: 'Moscow, Tverskaya' + # "AddressDetails": { + # "Country": { + # "AddressLine": "Moscow, Tverskaya Street", + # "CountryNameCode": "RU", + # "CountryName": "Russia", + # "AdministrativeArea": { + # "AdministrativeAreaName": "Moscow", + # "Locality": { + # "LocalityName": "Moscow", + # "Thoroughfare": { + # "ThoroughfareName": "Tverskaya Street" + # } + # } + # } + # } + # } + + ADMIN_LEVEL = %w[ + GeoObject metaDataProperty GeocoderMetaData + AddressDetails Country + AdministrativeArea + ].freeze + + # On SUBADMIN_LEVEL (may refer to urban district) + # example: 'Moscow Region, Krasnogorsk' + # "AddressDetails": { + # "Country": { + # "AddressLine": "Moscow Region, Krasnogorsk", + # "CountryNameCode": "RU", + # "CountryName": "Russia", + # "AdministrativeArea": { + # "AdministrativeAreaName": "Moscow Region", + # "SubAdministrativeArea": { + # "SubAdministrativeAreaName": "gorodskoy okrug Krasnogorsk", + # "Locality": { + # "LocalityName": "Krasnogorsk" + # } + # } + # } + # } + # } + + SUBADMIN_LEVEL = %w[ + GeoObject metaDataProperty GeocoderMetaData + AddressDetails Country + AdministrativeArea + SubAdministrativeArea + ].freeze + + # On DEPENDENT_LOCALITY_1 (may refer to district of city) + # example: 'Paris, Etienne Marcel' + # "AddressDetails": { + # "Country": { + # "AddressLine": "Île-de-France, Paris, 1er Arrondissement, Rue Étienne Marcel", + # "CountryNameCode": "FR", + # "CountryName": "France", + # "AdministrativeArea": { + # "AdministrativeAreaName": "Île-de-France", + # "Locality": { + # "LocalityName": "Paris", + # "DependentLocality": { + # "DependentLocalityName": "1er Arrondissement", + # "Thoroughfare": { + # "ThoroughfareName": "Rue Étienne Marcel" + # } + # } + # } + # } + # } + # } + + DEPENDENT_LOCALITY_1 = %w[ + GeoObject metaDataProperty GeocoderMetaData + AddressDetails Country + AdministrativeArea Locality + DependentLocality + ].freeze + + # On DEPENDENT_LOCALITY_2 (for special cases like turkish "mahalle") + # https://en.wikipedia.org/wiki/Mahalle + # example: 'Istanbul Mabeyinci Yokuşu 17' + + # "AddressDetails": { + # "Country": { + # "AddressLine": "İstanbul, Fatih, Saraç İshak Mah., Mabeyinci Yokuşu, 17", + # "CountryNameCode": "TR", + # "CountryName": "Turkey", + # "AdministrativeArea": { + # "AdministrativeAreaName": "İstanbul", + # "SubAdministrativeArea": { + # "SubAdministrativeAreaName": "Fatih", + # "Locality": { + # "DependentLocality": { + # "DependentLocalityName": "Saraç İshak Mah.", + # "Thoroughfare": { + # "ThoroughfareName": "Mabeyinci Yokuşu", + # "Premise": { + # "PremiseNumber": "17" + # } + # } + # } + # } + # } + # } + # } + # } + + DEPENDENT_LOCALITY_2 = %w[ + GeoObject metaDataProperty GeocoderMetaData + AddressDetails Country + AdministrativeArea + SubAdministrativeArea Locality + DependentLocality + ].freeze def coordinates @data['GeoObject']['Point']['pos'].split(' ').reverse.map(&:to_f) end - def address(format = :full) + def address(_format = :full) @data['GeoObject']['metaDataProperty']['GeocoderMetaData']['text'] end def city - if state.empty? and address_details and address_details.has_key? 'Locality' - address_details['Locality']['LocalityName'] - elsif sub_state.empty? and address_details and address_details.has_key? 'AdministrativeArea' and - address_details['AdministrativeArea'].has_key? 'Locality' - address_details['AdministrativeArea']['Locality']['LocalityName'] - elsif not sub_state_city.empty? - sub_state_city - else - "" - end + result = + if state.empty? + find_in_hash(@data, *COUNTRY_LEVEL, 'Locality', 'LocalityName') + elsif sub_state.empty? + find_in_hash(@data, *ADMIN_LEVEL, 'Locality', 'LocalityName') + else + find_in_hash(@data, *SUBADMIN_LEVEL, 'Locality', 'LocalityName') + end + + result || "" end def country - if address_details - address_details['CountryName'] - else - "" - end + find_in_hash(@data, *COUNTRY_LEVEL, 'CountryName') || "" end def country_code - if address_details - address_details['CountryNameCode'] - else - "" - end + find_in_hash(@data, *COUNTRY_LEVEL, 'CountryNameCode') || "" end def state - if address_details and address_details['AdministrativeArea'] - address_details['AdministrativeArea']['AdministrativeAreaName'] - else - "" - end + find_in_hash(@data, *ADMIN_LEVEL, 'AdministrativeAreaName') || "" end def sub_state - if !state.empty? and address_details and address_details['AdministrativeArea']['SubAdministrativeArea'] - address_details['AdministrativeArea']['SubAdministrativeArea']['SubAdministrativeAreaName'] - else - "" - end + return "" if state.empty? + find_in_hash(@data, *SUBADMIN_LEVEL, 'SubAdministrativeAreaName') || "" end def state_code "" end - def postal_code - "" + def street + thoroughfare_data.is_a?(Hash) ? thoroughfare_data['ThoroughfareName'] : "" end - def premise_name - address_details['Locality']['Premise']['PremiseName'] + def street_number + premise.is_a?(Hash) ? premise.fetch('PremiseNumber', "") : "" end - def street - thoroughfare_data && thoroughfare_data['ThoroughfareName'] + def premise_name + premise.is_a?(Hash) ? premise.fetch('PremiseName', "") : "" end - def street_number - thoroughfare_data && thoroughfare_data['Premise'] && thoroughfare_data['Premise']['PremiseNumber'] + def postal_code + return "" unless premise.is_a?(Hash) + find_in_hash(premise, 'PostalCode', 'PostalCodeNumber') || "" end def kind @@ -93,42 +238,55 @@ def viewport private # ---------------------------------------------------------------- - def thoroughfare_data - locality_data && locality_data['Thoroughfare'] + def top_level_locality + find_in_hash(@data, *ADDRESS_DETAILS, 'Locality') end - def locality_data - dependent_locality && subadmin_locality && admin_locality + def country_level_locality + find_in_hash(@data, *COUNTRY_LEVEL, 'Locality') end def admin_locality - address_details && address_details['AdministrativeArea'] && - address_details['AdministrativeArea']['Locality'] + find_in_hash(@data, *ADMIN_LEVEL, 'Locality') end def subadmin_locality - address_details && address_details['AdministrativeArea'] && - address_details['AdministrativeArea']['SubAdministrativeArea'] && - address_details['AdministrativeArea']['SubAdministrativeArea']['Locality'] + find_in_hash(@data, *SUBADMIN_LEVEL, 'Locality') end def dependent_locality - address_details && address_details['AdministrativeArea'] && - address_details['AdministrativeArea']['SubAdministrativeArea'] && - address_details['AdministrativeArea']['SubAdministrativeArea']['Locality'] && - address_details['AdministrativeArea']['SubAdministrativeArea']['Locality']['DependentLocality'] + find_in_hash(@data, *DEPENDENT_LOCALITY_1) || + find_in_hash(@data, *DEPENDENT_LOCALITY_2) + end + + def locality_data + dependent_locality || subadmin_locality || admin_locality || + country_level_locality || top_level_locality + end + + def thoroughfare_data + locality_data['Thoroughfare'] if locality_data.is_a?(Hash) end - def address_details - @data['GeoObject']['metaDataProperty']['GeocoderMetaData']['AddressDetails']['Country'] + def premise + if thoroughfare_data.is_a?(Hash) + thoroughfare_data['Premise'] + elsif locality_data.is_a?(Hash) + locality_data['Premise'] + end end - def sub_state_city - if !sub_state.empty? and address_details and address_details['AdministrativeArea']['SubAdministrativeArea'].has_key? 'Locality' - address_details['AdministrativeArea']['SubAdministrativeArea']['Locality']['LocalityName'] || "" - else - "" + def find_in_hash(source, *keys) + key = keys.shift + result = source[key] + + if keys.empty? + return result + elsif !result.is_a?(Hash) + return nil end + + find_in_hash(result, *keys) end end end diff --git a/lib/geocoder/sql.rb b/lib/geocoder/sql.rb index 71ea96f8a..6bca8a65a 100644 --- a/lib/geocoder/sql.rb +++ b/lib/geocoder/sql.rb @@ -44,13 +44,13 @@ def approx_distance(latitude, longitude, lat_attr, lon_attr, options = {}) end def within_bounding_box(sw_lat, sw_lng, ne_lat, ne_lng, lat_attr, lon_attr) - spans = "#{lat_attr} BETWEEN #{sw_lat} AND #{ne_lat} AND " + spans = "#{lat_attr} BETWEEN #{sw_lat.to_f} AND #{ne_lat.to_f} AND " # handle box that spans 180 longitude if sw_lng.to_f > ne_lng.to_f - spans + "(#{lon_attr} BETWEEN #{sw_lng} AND 180 OR " + - "#{lon_attr} BETWEEN -180 AND #{ne_lng})" + spans + "(#{lon_attr} BETWEEN #{sw_lng.to_f} AND 180 OR " + + "#{lon_attr} BETWEEN -180 AND #{ne_lng.to_f})" else - spans + "#{lon_attr} BETWEEN #{sw_lng} AND #{ne_lng}" + spans + "#{lon_attr} BETWEEN #{sw_lng.to_f} AND #{ne_lng.to_f}" end end diff --git a/lib/geocoder/stores/active_record.rb b/lib/geocoder/stores/active_record.rb index 0f2187a07..be7870c27 100644 --- a/lib/geocoder/stores/active_record.rb +++ b/lib/geocoder/stores/active_record.rb @@ -60,7 +60,7 @@ def self.included(base) # corner followed by the northeast corner of the box # (<tt>[[sw_lat, sw_lon], [ne_lat, ne_lon]]</tt>). # - scope :within_bounding_box, lambda{ |bounds| + scope :within_bounding_box, lambda{ |*bounds| sw_lat, sw_lng, ne_lat, ne_lng = bounds.flatten if bounds if sw_lat && sw_lng && ne_lat && ne_lng where(Geocoder::Sql.within_bounding_box( @@ -87,8 +87,6 @@ def distance_from_sql(location, *args) end end - private # ---------------------------------------------------------------- - ## # Get options hash suitable for passing to ActiveRecord.find to get # records within a radius (in kilometers) of the given point. diff --git a/lib/geocoder/stores/base.rb b/lib/geocoder/stores/base.rb index 9e49d48dd..048b62e12 100644 --- a/lib/geocoder/stores/base.rb +++ b/lib/geocoder/stores/base.rb @@ -90,7 +90,7 @@ def do_lookup(reverse = false) return end - query_options = [:lookup, :ip_lookup, :language].inject({}) do |hash, key| + query_options = [:lookup, :ip_lookup, :language, :params].inject({}) do |hash, key| if options.has_key?(key) val = options[key] hash[key] = val.respond_to?(:call) ? val.call(self) : val diff --git a/lib/geocoder/version.rb b/lib/geocoder/version.rb index 29ea0404a..6f3e16be6 100644 --- a/lib/geocoder/version.rb +++ b/lib/geocoder/version.rb @@ -1,3 +1,3 @@ module Geocoder - VERSION = "1.4.5" + VERSION = "1.6.3" end diff --git a/lib/hash_recursive_merge.rb b/lib/hash_recursive_merge.rb index 163566ee1..49d648ce3 100644 --- a/lib/hash_recursive_merge.rb +++ b/lib/hash_recursive_merge.rb @@ -60,9 +60,8 @@ def rmerge!(other_hash) # h1.merge(h2) #=> {"a" => 100, "b" = >254, "c" => {"c1" => 16, "c3" => 94}} # def rmerge(other_hash) - r = {} merge(other_hash) do |key, oldval, newval| - r[key] = oldval.class == self.class ? oldval.rmerge(newval) : newval + oldval.class == self.class ? oldval.rmerge(newval) : newval end end diff --git a/lib/maxmind_database.rb b/lib/maxmind_database.rb index 471195a44..9330f03f6 100644 --- a/lib/maxmind_database.rb +++ b/lib/maxmind_database.rb @@ -96,9 +96,9 @@ def archive_url(package) def archive_url_path(package) { - geolite_country_csv: "GeoIPCountryCSV.zip", - geolite_city_csv: "GeoLiteCity_CSV/GeoLiteCity-latest.zip", - geolite_asn_csv: "asnum/GeoIPASNum2.zip" + geolite_country_csv: "GeoLite2-Country-CSV.zip", + geolite_city_csv: "GeoLite2-City-CSV.zip", + geolite_asn_csv: "GeoLite2-ASN-CSV.zip" }[package] end diff --git a/test/database.yml b/test/database.yml index 63232ed58..f5f96de5f 100644 --- a/test/database.yml +++ b/test/database.yml @@ -11,4 +11,4 @@ mysql: postgres: adapter: postgresql database: geocoder_test - username: + username: postgres diff --git a/test/fixtures/bing_forbidden_request b/test/fixtures/bing_forbidden_request new file mode 100644 index 000000000..6736e6abf --- /dev/null +++ b/test/fixtures/bing_forbidden_request @@ -0,0 +1,16 @@ +{ + "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":403, + "statusDescription":"OK", + "traceId":"907b76a307bc49129a489de3d4c992ea|CH1M001463|02.00.82.2800|CH1MSNVM001383, CH1MSNVM001358, CH1MSNVM001397" +} diff --git a/test/fixtures/bing_internal_server_error b/test/fixtures/bing_internal_server_error new file mode 100644 index 000000000..8abd2c4d6 --- /dev/null +++ b/test/fixtures/bing_internal_server_error @@ -0,0 +1,16 @@ +{ + "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":500, + "statusDescription":"OK", + "traceId":"907b76a307bc49129a489de3d4c992ea|CH1M001463|02.00.82.2800|CH1MSNVM001383, CH1MSNVM001358, CH1MSNVM001397" +} diff --git a/test/fixtures/freegeoip_74_200_247_59 b/test/fixtures/freegeoip_74_200_247_59 index e187b40bd..defc4ace5 100644 --- a/test/fixtures/freegeoip_74_200_247_59 +++ b/test/fixtures/freegeoip_74_200_247_59 @@ -4,9 +4,9 @@ "region_name": "Texas", "metro_code": "623", "zipcode": "75093", - "longitude": "-96.8134", + "longitude": -96.8134, "country_name": "United States", "country_code": "US", "ip": "74.200.247.59", - "latitude": "33.0347" + "latitude": 33.0347 } diff --git a/test/fixtures/geocoder_ca_madison_square_garden b/test/fixtures/geocoder_ca_madison_square_garden index 7592108f6..b7bb6b720 100644 --- a/test/fixtures/geocoder_ca_madison_square_garden +++ b/test/fixtures/geocoder_ca_madison_square_garden @@ -1 +1 @@ -test({"longt":"-73.992006","latt":"40.749101"}); +test({ "standard" : { "staddress" : "Madison Square Garden", "stnumber" : "1", "prov" : "NY", "city" : "New York", "confidence" : "0.9" }, "longt" : "-73.994240", "latt" : "40.750050"}); diff --git a/test/fixtures/geocoder_us_madison_square_garden b/test/fixtures/geocoder_us_madison_square_garden deleted file mode 100644 index 546df3682..000000000 --- a/test/fixtures/geocoder_us_madison_square_garden +++ /dev/null @@ -1 +0,0 @@ -40.678107, -73.897460, 4 Pennsylvania Ave, New York, NY, 11207 \ No newline at end of file diff --git a/test/fixtures/geocoder_us_no_results b/test/fixtures/geocoder_us_no_results deleted file mode 100644 index d349a8f91..000000000 --- a/test/fixtures/geocoder_us_no_results +++ /dev/null @@ -1 +0,0 @@ -2: couldn't find this address! sorry \ No newline at end of file diff --git a/test/fixtures/google_new_york b/test/fixtures/google_new_york new file mode 100644 index 000000000..0de608f16 --- /dev/null +++ b/test/fixtures/google_new_york @@ -0,0 +1,64 @@ +{ + "status": "OK", + "results": [ { + "address_components": [ + { + "long_name": "New York", + "short_name": "New York", + "types": [ + "locality", + "political" + ] + }, + { + "long_name": "New York", + "short_name": "NY", + "types": [ + "administrative_area_level_1", + "political" + ] + }, + { + "long_name": "United States", + "short_name": "US", + "types": [ + "country", + "political" + ] + } + ], + "formatted_address": "New York, NY, USA", + "geometry": { + "bounds": { + "northeast": { + "lat": 40.9175771, + "lng": -73.7002721 + }, + "southwest": { + "lat": 40.4773991, + "lng": -74.2590899 + } + }, + "location": { + "lat": 40.7127837, + "lng": -74.0059413 + }, + "location_type": "APPROXIMATE", + "viewport": { + "northeast": { + "lat": 40.9152555, + "lng": -73.7002721 + }, + "southwest": { + "lat": 40.4960439, + "lng": -74.2557349 + } + } + }, + "place_id": "ChIJOwg_06VPwokRYv534QaPC8g", + "types": [ + "locality", + "political" + ] + } ] +} diff --git a/test/fixtures/ip2location_8_8_8_8 b/test/fixtures/ip2location_8_8_8_8 new file mode 100644 index 000000000..84d967d69 --- /dev/null +++ b/test/fixtures/ip2location_8_8_8_8 @@ -0,0 +1,22 @@ +{ + "country_code":"US", + "country_name":"United States", + "region_name":"California", + "city_name":"Mountain View", + "latitude":"37.405992", + "longitude":"-122.078515", + "zip_code":"94043", + "time_zone":"-07:00", + "isp":"Google LLC", + "domain":"google.com", + "net_speed":"T1", + "idd_code":"1", + "area_code":"650", + "weather_station_code":"USCA0746", + "weather_station_name":"Mountain View", + "mcc":"-", + "mnc":"-", + "mobile_brand":"-", + "elevation":"31", + "usage_type":"DCH" +} \ No newline at end of file diff --git a/test/fixtures/ip2location_invalid_api_key b/test/fixtures/ip2location_invalid_api_key new file mode 100644 index 000000000..698205b4f --- /dev/null +++ b/test/fixtures/ip2location_invalid_api_key @@ -0,0 +1,3 @@ +{ + "response":"INVALID ACCOUNT" +} \ No newline at end of file diff --git a/test/fixtures/ip2location_no_results b/test/fixtures/ip2location_no_results new file mode 100644 index 000000000..e69de29bb diff --git a/test/fixtures/ipdata_co_74_200_247_59 b/test/fixtures/ipdata_co_74_200_247_59 new file mode 100644 index 000000000..a2da12b53 --- /dev/null +++ b/test/fixtures/ipdata_co_74_200_247_59 @@ -0,0 +1,24 @@ +{ + "ip": "74.200.247.59", + "city": "Jersey City", + "region": "New Jersey", + "region_code": "NJ", + "country_name": "United States", + "country_code": "US", + "continent_name": "North America", + "continent_code": "NA", + "latitude": 40.7209, + "longitude": -74.0468, + "asn": "AS22576", + "organisation": "DataPipe, Inc.", + "postal": "07302", + "currency": "USD", + "currency_symbol": "$", + "calling_code": "1", + "flag": "https://ipdata.co/flags/us.png", + "time_zone": "America/New_York", + "is_eu": false, + "suspicious_factors": { + "is_tor": false + } +} \ No newline at end of file diff --git a/test/fixtures/ipdata_co_8_8_8 b/test/fixtures/ipdata_co_8_8_8 new file mode 100644 index 000000000..2462e1270 --- /dev/null +++ b/test/fixtures/ipdata_co_8_8_8 @@ -0,0 +1 @@ +8.8.8 does not appear to be an IPv4 or IPv6 address \ No newline at end of file diff --git a/test/fixtures/ipdata_co_no_results b/test/fixtures/ipdata_co_no_results new file mode 100644 index 000000000..896eaf563 --- /dev/null +++ b/test/fixtures/ipdata_co_no_results @@ -0,0 +1 @@ +0.0.0 does not appear to be an IPv4 or IPv6 address \ No newline at end of file diff --git a/test/fixtures/ipgeolocation_103_217_177_217 b/test/fixtures/ipgeolocation_103_217_177_217 new file mode 100644 index 000000000..d4e6e04ca --- /dev/null +++ b/test/fixtures/ipgeolocation_103_217_177_217 @@ -0,0 +1,37 @@ +{ + "ip": "103.217.177.217", + "continent_code": "AS", + "continent_name": "Asia", + "country_code2": "PK", + "country_code3": "PAK", + "country_name": "Pakistan", + "country_capital": "Islamabad", + "state_prov": "Islamabad", + "district": "Islamabad", + "city": "Islamabad", + "zipcode": "44000", + "latitude": "33.7334", + "longitude": "73.0785", + "is_eu": false, + "calling_code": "+92", + "country_tld": ".pk", + "languages": "ur-PK,en-PK,pa,sd,ps,brh", + "country_flag": "https://ipgeolocation.io/static/flags/pk_64.png", + "isp": "TES", + "connection_type": "", + "organization": "Trans World Enterprise Services (Private) Limited", + "geoname_id": "1162015", + "currency": { + "code": "PKR", + "name": "Pakistan Rupee", + "symbol": "₨" + }, + "time_zone": { + "name": "Asia/Karachi", + "offset": 5, + "current_time": "2019-03-18 19:28:33.837+0500", + "current_time_unix": 1552919313.837, + "is_dst": false, + "dst_savings": 0 + } +} \ No newline at end of file diff --git a/test/fixtures/ipgeolocation_invalid_api_key b/test/fixtures/ipgeolocation_invalid_api_key new file mode 100644 index 000000000..09ae15f77 --- /dev/null +++ b/test/fixtures/ipgeolocation_invalid_api_key @@ -0,0 +1 @@ +{"message":"Provided API key is not valid."} diff --git a/test/fixtures/ipregistry_8_8_8_8 b/test/fixtures/ipregistry_8_8_8_8 new file mode 100644 index 000000000..28422626c --- /dev/null +++ b/test/fixtures/ipregistry_8_8_8_8 @@ -0,0 +1,108 @@ +{ + "ip" : "8.8.8.8", + "type" : "IPv4", + "hostname" : null, + "carrier" : { + "name" : null, + "mcc" : null, + "mnc" : null + }, + "connection" : { + "asn" : 15169, + "domain" : "google.com", + "organization" : "Google LLC", + "type" : "hosting" + }, + "currency" : { + "code" : "USD", + "name" : "US Dollar", + "plural" : "US dollars", + "symbol" : "$", + "symbol_native" : "$", + "format" : { + "negative" : { + "prefix" : "-$", + "suffix" : "" + }, + "positive" : { + "prefix" : "$", + "suffix" : "" + } + } + }, + "location" : { + "continent" : { + "code" : "NA", + "name" : "North America" + }, + "country" : { + "area" : 9629091.0, + "borders" : [ "CA", "MX" ], + "calling_code" : "1", + "capital" : "Washington D.C.", + "code" : "US", + "name" : "United States", + "population" : 327167434, + "population_density" : 33.98, + "flag" : { + "emoji" : "🇺🇸", + "emoji_unicode" : "U+1F1FA U+1F1F8", + "emojitwo" : "https://cdn.ipregistry.co/flags/emojitwo/us.svg", + "noto" : "https://cdn.ipregistry.co/flags/noto/us.png", + "twemoji" : "https://cdn.ipregistry.co/flags/twemoji/us.svg", + "wikimedia" : "https://cdn.ipregistry.co/flags/wikimedia/us.svg" + }, + "languages" : [ { + "code" : "en", + "name" : "English", + "native" : "English" + }, { + "code" : "es", + "name" : "Spanish", + "native" : "español" + }, { + "code" : "haw", + "name" : "Hawaiian", + "native" : "ʻŌlelo Hawaiʻi" + }, { + "code" : "fr", + "name" : "French", + "native" : "français" + } ], + "tld" : ".us" + }, + "region" : { + "code" : "CA", + "name" : "California" + }, + "city" : "Mountain View", + "postal" : "94043", + "latitude" : 37.405992, + "longitude" : -122.078515, + "language" : { + "code" : "en", + "name" : "English", + "native" : "English" + }, + "in_eu" : false + }, + "security" : { + "is_bogon" : false, + "is_cloud_provider" : true, + "is_tor" : false, + "is_tor_exit" : false, + "is_proxy" : false, + "is_anonymous" : false, + "is_abuser" : false, + "is_attacker" : false, + "is_threat" : true + }, + "time_zone" : { + "id" : "America/Los_Angeles", + "abbreviation" : "PST", + "current_time" : "2019-08-18T22:09:10-07:00", + "name" : "Pacific Standard Time", + "offset" : -25200, + "in_daylight_saving" : true + } +} \ No newline at end of file diff --git a/test/fixtures/ipregistry_no_results b/test/fixtures/ipregistry_no_results new file mode 100644 index 000000000..e69de29bb diff --git a/test/fixtures/ipstack_134_201_250_155 b/test/fixtures/ipstack_134_201_250_155 new file mode 100644 index 000000000..cff0568d2 --- /dev/null +++ b/test/fixtures/ipstack_134_201_250_155 @@ -0,0 +1,49 @@ +{ + "ip": "134.201.250.155", + "hostname": "134.201.250.155", + "type": "ipv4", + "continent_code": "NA", + "continent_name": "North America", + "country_code": "US", + "country_name": "United States", + "region_code": "CA", + "region_name": "California", + "city": "Los Angeles", + "zip": "90013", + "latitude": 34.0453, + "longitude": -118.2413, + "location": { + "geoname_id": 5368361, + "capital": "Washington D.C.", + "languages": [ + { + "code": "en", + "name": "English", + "native": "English" + } + ], + "country_flag": "https://assets.ipstack.com/images/assets/flags_svg/us.svg", + "country_flag_emoji": "🇺🇸", + "country_flag_emoji_unicode": "U+1F1FA U+1F1F8", + "calling_code": "1", + "is_eu": false + }, + "time_zone": { + "id": "America/Los_Angeles", + "current_time": "2018-03-29T07:35:08-07:00", + "gmt_offset": -25200, + "code": "PDT", + "is_daylight_saving": true + }, + "currency": { + "code": "USD", + "name": "US Dollar", + "plural": "US dollars", + "symbol": "$", + "symbol_native": "$" + }, + "connection": { + "asn": 25876, + "isp": "Los Angeles Department of Water & Power" + } +} diff --git a/test/fixtures/ipstack_access_restricted b/test/fixtures/ipstack_access_restricted new file mode 100644 index 000000000..652e1cb9c --- /dev/null +++ b/test/fixtures/ipstack_access_restricted @@ -0,0 +1,8 @@ +{ + "success": false, + "error": { + "code": 105, + "type": "function_access_restricted", + "info": "The current subscription plan does not support this API endpoint." + } +} \ No newline at end of file diff --git a/test/fixtures/ipstack_batch_not_supported b/test/fixtures/ipstack_batch_not_supported new file mode 100644 index 000000000..b60a245f3 --- /dev/null +++ b/test/fixtures/ipstack_batch_not_supported @@ -0,0 +1,8 @@ +{ + "success": false, + "error": { + "code": 303, + "type": "batch_not_supported_on_plan", + "info": "The Bulk Lookup Endpoint is not supported on the current subscription plan" + } +} \ No newline at end of file diff --git a/test/fixtures/ipstack_inactive_user b/test/fixtures/ipstack_inactive_user new file mode 100644 index 000000000..1ead8fa9e --- /dev/null +++ b/test/fixtures/ipstack_inactive_user @@ -0,0 +1,8 @@ +{ + "success": false, + "error": { + "code": 102, + "type": "inactive_user", + "info": "The current user account is not active. User will be prompted to get in touch with Customer Support." + } +} \ No newline at end of file diff --git a/test/fixtures/ipstack_invalid_access_key b/test/fixtures/ipstack_invalid_access_key new file mode 100644 index 000000000..f119c8521 --- /dev/null +++ b/test/fixtures/ipstack_invalid_access_key @@ -0,0 +1,8 @@ +{ + "success": false, + "error": { + "code": 101, + "type": "invalid_access_key", + "info": "No API Key was specified or an invalid API Key was specified." + } +} \ No newline at end of file diff --git a/test/fixtures/ipstack_invalid_api_function b/test/fixtures/ipstack_invalid_api_function new file mode 100644 index 000000000..e58000501 --- /dev/null +++ b/test/fixtures/ipstack_invalid_api_function @@ -0,0 +1,8 @@ +{ + "success": false, + "error": { + "code": 103, + "type": "invalid_api_function", + "info": "The requested API endpoint does not exist." + } +} \ No newline at end of file diff --git a/test/fixtures/ipstack_invalid_fields b/test/fixtures/ipstack_invalid_fields new file mode 100644 index 000000000..105f54119 --- /dev/null +++ b/test/fixtures/ipstack_invalid_fields @@ -0,0 +1,8 @@ +{ + "success": false, + "error": { + "code": 301, + "type": "invalid_fields", + "info": "One or more invalid fields were specified using the fields parameter." + } +} \ No newline at end of file diff --git a/test/fixtures/ipstack_missing_access_key b/test/fixtures/ipstack_missing_access_key new file mode 100644 index 000000000..358e5c8e0 --- /dev/null +++ b/test/fixtures/ipstack_missing_access_key @@ -0,0 +1,8 @@ +{ + "success": false, + "error": { + "code": 101, + "type": "missing_access_key", + "info": "No API Key was specified." + } +} \ No newline at end of file diff --git a/test/fixtures/ipstack_no_results b/test/fixtures/ipstack_no_results new file mode 100644 index 000000000..e69de29bb diff --git a/test/fixtures/ipstack_not_found b/test/fixtures/ipstack_not_found new file mode 100644 index 000000000..f644fa30a --- /dev/null +++ b/test/fixtures/ipstack_not_found @@ -0,0 +1,8 @@ +{ + "success": false, + "error": { + "code": 404, + "type": "404_not_found", + "info": "The requested resource does not exist." + } +} \ No newline at end of file diff --git a/test/fixtures/ipstack_protocol_access_restricted b/test/fixtures/ipstack_protocol_access_restricted new file mode 100644 index 000000000..7c915afaf --- /dev/null +++ b/test/fixtures/ipstack_protocol_access_restricted @@ -0,0 +1,8 @@ +{ + "success": false, + "error": { + "code": 105, + "type": "https_access_restricted", + "info": "The user's current subscription plan does not support HTTPS Encryption." + } +} \ No newline at end of file diff --git a/test/fixtures/ipstack_too_many_ips b/test/fixtures/ipstack_too_many_ips new file mode 100644 index 000000000..b85c5e5d1 --- /dev/null +++ b/test/fixtures/ipstack_too_many_ips @@ -0,0 +1,8 @@ +{ + "success": false, + "error": { + "code": 302, + "type": "too_many_ips", + "info": "Too many IPs have been specified for the Bulk Lookup Endpoint. (max. 50)" + } +} \ No newline at end of file diff --git a/test/fixtures/ipstack_usage_limit b/test/fixtures/ipstack_usage_limit new file mode 100644 index 000000000..d3753f02a --- /dev/null +++ b/test/fixtures/ipstack_usage_limit @@ -0,0 +1,8 @@ +{ + "success": false, + "error": { + "code": 104, + "type": "usage_limit_reached", + "info": "The maximum allowed amount of monthly API requests has been reached." + } +} \ No newline at end of file diff --git a/test/fixtures/nationaal_georegister_nl b/test/fixtures/nationaal_georegister_nl new file mode 100644 index 000000000..a41c0cad2 --- /dev/null +++ b/test/fixtures/nationaal_georegister_nl @@ -0,0 +1,441 @@ +{ + "response": { + "numFound": 10242, + "start": 0, + "maxScore": 61.028397, + "docs": [ + { + "bron": "BAG", + "woonplaatscode": "3594", + "type": "adres", + "woonplaatsnaam": "Amsterdam", + "wijkcode": "WK036301", + "huis_nlt": "147", + "openbareruimtetype": "Weg", + "buurtnaam": "Nieuwe Kerk e.o.", + "gemeentecode": "0363", + "rdf_seealso": "http://bag.basisregistraties.overheid.nl/bag/id/nummeraanduiding/0363200000218908", + "weergavenaam": "Nieuwezijds Voorburgwal 147, 1012RJ Amsterdam", + "suggest": [ + "Nieuwezijds Voorburgwal 147, 1012RJ Amsterdam", + "Nieuwezijds Voorburgwal 147, 1012 RJ Amsterdam" + ], + "straatnaam_verkort": "Nieuwezijds Voorburgwal", + "id": "adr-563f90756e46d1c554b4ab00ac61b932", + "gekoppeld_perceel": [ + "ASD04-F-2749" + ], + "gemeentenaam": "Amsterdam", + "buurtcode": "BU03630104", + "wijknaam": "Burgwallen-Nieuwe Zijde", + "identificatie": "0363010000758545-0363200000218908", + "openbareruimte_id": "0363300000004690", + "waterschapsnaam": "HH Amstel, Gooi en Vecht", + "provinciecode": "PV27", + "postcode": "1012RJ", + "provincienaam": "Noord-Holland", + "geometrie_ll": "POINT(4.89089949 52.37316397)", + "centroide_ll": "POINT(4.89089949 52.37316397)", + "nummeraanduiding_id": "0363200000218908", + "waterschapscode": "31", + "adresseerbaarobject_id": "0363010000758545", + "huisnummer": 147, + "provincieafkorting": "NH", + "centroide_rd": "POINT(121202 487370)", + "geometrie_rd": "POINT(121202 487370)", + "straatnaam": "Nieuwezijds Voorburgwal", + "_version_": 1627309871432990700, + "typesortering": 4, + "sortering": 147, + "shard": "bag" + }, + { + "bron": "BAG", + "suggest": [ + "Nieuwezijds Voorburgwal, 1012 RJ Amsterdam", + "Nieuwezijds Voorburgwal, 1012RJ Amsterdam" + ], + "woonplaatscode": "3594", + "type": "postcode", + "woonplaatsnaam": "Amsterdam", + "openbareruimtetype": "Weg", + "gemeentecode": "0363", + "weergavenaam": "Nieuwezijds Voorburgwal, 1012RJ Amsterdam", + "straatnaam_verkort": "Nieuwezijds Voorburgwal", + "id": "pcd-07ad1c9a6086b4ffd4b885b4cc12f513", + "gemeentenaam": "Amsterdam", + "identificatie": "0363300000004690_1012RJ", + "openbareruimte_id": "0363300000004690", + "provinciecode": "PV27", + "postcode": "1012RJ", + "provincienaam": "Noord-Holland", + "geometrie_ll": "POINT(4.89133064 52.3739109)", + "centroide_ll": "POINT(4.89133064 52.3739109)", + "provincieafkorting": "NH", + "centroide_rd": "POINT(121231.93 487452.904)", + "geometrie_rd": "POINT(121231.93 487452.904)", + "straatnaam": "Nieuwezijds Voorburgwal", + "_version_": 1627316920607834000, + "typesortering": 3.5, + "shard": "bag" + }, + { + "bron": "BAG", + "woonplaatscode": "3594", + "type": "adres", + "woonplaatsnaam": "Amsterdam", + "wijkcode": "WK036301", + "huis_nlt": "125", + "openbareruimtetype": "Weg", + "buurtnaam": "Nieuwe Kerk e.o.", + "gemeentecode": "0363", + "rdf_seealso": "http://bag.basisregistraties.overheid.nl/bag/id/nummeraanduiding/0363200000218874", + "weergavenaam": "Nieuwezijds Voorburgwal 125, 1012RJ Amsterdam", + "suggest": [ + "Nieuwezijds Voorburgwal 125, 1012RJ Amsterdam", + "Nieuwezijds Voorburgwal 125, 1012 RJ Amsterdam" + ], + "straatnaam_verkort": "Nieuwezijds Voorburgwal", + "id": "adr-00c3407685fcd67989bb2915acdee929", + "gekoppeld_perceel": [ + "ASD04-F-2732" + ], + "gemeentenaam": "Amsterdam", + "buurtcode": "BU03630104", + "wijknaam": "Burgwallen-Nieuwe Zijde", + "identificatie": "0363010000758517-0363200000218874", + "openbareruimte_id": "0363300000004690", + "waterschapsnaam": "HH Amstel, Gooi en Vecht", + "provinciecode": "PV27", + "postcode": "1012RJ", + "provincienaam": "Noord-Holland", + "geometrie_ll": "POINT(4.89153483 52.37412832)", + "centroide_ll": "POINT(4.89153483 52.37412832)", + "nummeraanduiding_id": "0363200000218874", + "waterschapscode": "31", + "adresseerbaarobject_id": "0363010000758517", + "huisnummer": 125, + "provincieafkorting": "NH", + "centroide_rd": "POINT(121246 487477)", + "geometrie_rd": "POINT(121246 487477)", + "straatnaam": "Nieuwezijds Voorburgwal", + "_version_": 1627309871418310700, + "typesortering": 4, + "sortering": 125, + "shard": "bag" + }, + { + "bron": "BAG", + "woonplaatscode": "3594", + "type": "adres", + "woonplaatsnaam": "Amsterdam", + "wijkcode": "WK036301", + "huis_nlt": "127", + "openbareruimtetype": "Weg", + "buurtnaam": "Nieuwe Kerk e.o.", + "gemeentecode": "0363", + "rdf_seealso": "http://bag.basisregistraties.overheid.nl/bag/id/nummeraanduiding/0363200012076682", + "weergavenaam": "Nieuwezijds Voorburgwal 127, 1012RJ Amsterdam", + "suggest": [ + "Nieuwezijds Voorburgwal 127, 1012RJ Amsterdam", + "Nieuwezijds Voorburgwal 127, 1012 RJ Amsterdam" + ], + "straatnaam_verkort": "Nieuwezijds Voorburgwal", + "id": "adr-bb2a9b0c4090656cd8a31e3cdfa26701", + "gekoppeld_perceel": [ + "ASD04-F-2731" + ], + "gemeentenaam": "Amsterdam", + "buurtcode": "BU03630104", + "wijknaam": "Burgwallen-Nieuwe Zijde", + "identificatie": "0363010012076291-0363200012076682", + "openbareruimte_id": "0363300000004690", + "waterschapsnaam": "HH Amstel, Gooi en Vecht", + "provinciecode": "PV27", + "postcode": "1012RJ", + "provincienaam": "Noord-Holland", + "geometrie_ll": "POINT(4.89147613 52.37412482)", + "centroide_ll": "POINT(4.89147613 52.37412482)", + "nummeraanduiding_id": "0363200012076682", + "waterschapscode": "31", + "adresseerbaarobject_id": "0363010012076291", + "huisnummer": 127, + "provincieafkorting": "NH", + "centroide_rd": "POINT(121242 487476.638)", + "geometrie_rd": "POINT(121242 487476.638)", + "straatnaam": "Nieuwezijds Voorburgwal", + "_version_": 1627310053758337000, + "typesortering": 4, + "sortering": 127, + "shard": "bag" + }, + { + "bron": "BAG", + "woonplaatscode": "3594", + "type": "adres", + "woonplaatsnaam": "Amsterdam", + "wijkcode": "WK036301", + "huis_nlt": "129", + "openbareruimtetype": "Weg", + "buurtnaam": "Nieuwe Kerk e.o.", + "gemeentecode": "0363", + "rdf_seealso": "http://bag.basisregistraties.overheid.nl/bag/id/nummeraanduiding/0363200012076683", + "weergavenaam": "Nieuwezijds Voorburgwal 129, 1012RJ Amsterdam", + "suggest": [ + "Nieuwezijds Voorburgwal 129, 1012RJ Amsterdam", + "Nieuwezijds Voorburgwal 129, 1012 RJ Amsterdam" + ], + "straatnaam_verkort": "Nieuwezijds Voorburgwal", + "id": "adr-e3339f855fd23024786c719e404fe9e8", + "gekoppeld_perceel": [ + "ASD04-F-2729" + ], + "gemeentenaam": "Amsterdam", + "buurtcode": "BU03630104", + "wijknaam": "Burgwallen-Nieuwe Zijde", + "identificatie": "0363010012076292-0363200012076683", + "openbareruimte_id": "0363300000004690", + "waterschapsnaam": "HH Amstel, Gooi en Vecht", + "provinciecode": "PV27", + "postcode": "1012RJ", + "provincienaam": "Noord-Holland", + "geometrie_ll": "POINT(4.89141948 52.37411589)", + "centroide_ll": "POINT(4.89141948 52.37411589)", + "nummeraanduiding_id": "0363200012076683", + "waterschapscode": "31", + "adresseerbaarobject_id": "0363010012076292", + "huisnummer": 129, + "provincieafkorting": "NH", + "centroide_rd": "POINT(121238.135 487475.671)", + "geometrie_rd": "POINT(121238.135 487475.671)", + "straatnaam": "Nieuwezijds Voorburgwal", + "_version_": 1627310053759385600, + "typesortering": 4, + "sortering": 129, + "shard": "bag" + }, + { + "bron": "BAG", + "woonplaatscode": "3594", + "type": "adres", + "woonplaatsnaam": "Amsterdam", + "wijkcode": "WK036301", + "huis_nlt": "133", + "openbareruimtetype": "Weg", + "buurtnaam": "Nieuwe Kerk e.o.", + "gemeentecode": "0363", + "rdf_seealso": "http://bag.basisregistraties.overheid.nl/bag/id/nummeraanduiding/0363200000218889", + "weergavenaam": "Nieuwezijds Voorburgwal 133, 1012RJ Amsterdam", + "suggest": [ + "Nieuwezijds Voorburgwal 133, 1012RJ Amsterdam", + "Nieuwezijds Voorburgwal 133, 1012 RJ Amsterdam" + ], + "straatnaam_verkort": "Nieuwezijds Voorburgwal", + "id": "adr-0c4f985c4b63168eb4327f76774deef1", + "gekoppeld_perceel": [ + "ASD04-F-7847" + ], + "gemeentenaam": "Amsterdam", + "buurtcode": "BU03630104", + "wijknaam": "Burgwallen-Nieuwe Zijde", + "identificatie": "0363010000758534-0363200000218889", + "openbareruimte_id": "0363300000004690", + "waterschapsnaam": "HH Amstel, Gooi en Vecht", + "provinciecode": "PV27", + "postcode": "1012RJ", + "provincienaam": "Noord-Holland", + "geometrie_ll": "POINT(4.89128581 52.37407335)", + "centroide_ll": "POINT(4.89128581 52.37407335)", + "nummeraanduiding_id": "0363200000218889", + "waterschapscode": "31", + "adresseerbaarobject_id": "0363010000758534", + "huisnummer": 133, + "provincieafkorting": "NH", + "centroide_rd": "POINT(121229 487471)", + "geometrie_rd": "POINT(121229 487471)", + "straatnaam": "Nieuwezijds Voorburgwal", + "_version_": 1627309871428796400, + "typesortering": 4, + "sortering": 133, + "shard": "bag" + }, + { + "bron": "BAG", + "woonplaatscode": "3594", + "type": "adres", + "woonplaatsnaam": "Amsterdam", + "wijkcode": "WK036301", + "huis_nlt": "135", + "openbareruimtetype": "Weg", + "buurtnaam": "Nieuwe Kerk e.o.", + "gemeentecode": "0363", + "rdf_seealso": "http://bag.basisregistraties.overheid.nl/bag/id/nummeraanduiding/0363200000218892", + "weergavenaam": "Nieuwezijds Voorburgwal 135, 1012RJ Amsterdam", + "suggest": [ + "Nieuwezijds Voorburgwal 135, 1012RJ Amsterdam", + "Nieuwezijds Voorburgwal 135, 1012 RJ Amsterdam" + ], + "straatnaam_verkort": "Nieuwezijds Voorburgwal", + "id": "adr-741c0d7a8cab9ea398e8e5de0fb6e841", + "gekoppeld_perceel": [ + "ASD04-F-7847" + ], + "gemeentenaam": "Amsterdam", + "buurtcode": "BU03630104", + "wijknaam": "Burgwallen-Nieuwe Zijde", + "identificatie": "0363010000758537-0363200000218892", + "openbareruimte_id": "0363300000004690", + "waterschapsnaam": "HH Amstel, Gooi en Vecht", + "provinciecode": "PV27", + "postcode": "1012RJ", + "provincienaam": "Noord-Holland", + "geometrie_ll": "POINT(4.89122747 52.37403716)", + "centroide_ll": "POINT(4.89122747 52.37403716)", + "nummeraanduiding_id": "0363200000218892", + "waterschapscode": "31", + "adresseerbaarobject_id": "0363010000758537", + "huisnummer": 135, + "provincieafkorting": "NH", + "centroide_rd": "POINT(121225 487467)", + "geometrie_rd": "POINT(121225 487467)", + "straatnaam": "Nieuwezijds Voorburgwal", + "_version_": 1627309871429845000, + "typesortering": 4, + "sortering": 135, + "shard": "bag" + }, + { + "bron": "BAG", + "woonplaatscode": "3594", + "type": "adres", + "woonplaatsnaam": "Amsterdam", + "wijkcode": "WK036301", + "huis_nlt": "137", + "openbareruimtetype": "Weg", + "buurtnaam": "Nieuwe Kerk e.o.", + "gemeentecode": "0363", + "rdf_seealso": "http://bag.basisregistraties.overheid.nl/bag/id/nummeraanduiding/0363200000218895", + "weergavenaam": "Nieuwezijds Voorburgwal 137, 1012RJ Amsterdam", + "suggest": [ + "Nieuwezijds Voorburgwal 137, 1012RJ Amsterdam", + "Nieuwezijds Voorburgwal 137, 1012 RJ Amsterdam" + ], + "straatnaam_verkort": "Nieuwezijds Voorburgwal", + "id": "adr-49b25fb1d14a09d548beb984452010a8", + "gekoppeld_perceel": [ + "ASD04-F-7847" + ], + "gemeentenaam": "Amsterdam", + "buurtcode": "BU03630104", + "wijknaam": "Burgwallen-Nieuwe Zijde", + "identificatie": "0363010000758540-0363200000218895", + "openbareruimte_id": "0363300000004690", + "waterschapsnaam": "HH Amstel, Gooi en Vecht", + "provinciecode": "PV27", + "postcode": "1012RJ", + "provincienaam": "Noord-Holland", + "geometrie_ll": "POINT(4.89116944 52.373974)", + "centroide_ll": "POINT(4.89116944 52.373974)", + "nummeraanduiding_id": "0363200000218895", + "waterschapscode": "31", + "adresseerbaarobject_id": "0363010000758540", + "huisnummer": 137, + "provincieafkorting": "NH", + "centroide_rd": "POINT(121221 487460)", + "geometrie_rd": "POINT(121221 487460)", + "straatnaam": "Nieuwezijds Voorburgwal", + "_version_": 1627309871430893600, + "typesortering": 4, + "sortering": 137, + "shard": "bag" + }, + { + "bron": "BAG", + "woonplaatscode": "3594", + "type": "adres", + "woonplaatsnaam": "Amsterdam", + "wijkcode": "WK036301", + "huis_nlt": "141", + "openbareruimtetype": "Weg", + "buurtnaam": "Nieuwe Kerk e.o.", + "gemeentecode": "0363", + "rdf_seealso": "http://bag.basisregistraties.overheid.nl/bag/id/nummeraanduiding/0363200000218902", + "weergavenaam": "Nieuwezijds Voorburgwal 141, 1012RJ Amsterdam", + "suggest": [ + "Nieuwezijds Voorburgwal 141, 1012RJ Amsterdam", + "Nieuwezijds Voorburgwal 141, 1012 RJ Amsterdam" + ], + "straatnaam_verkort": "Nieuwezijds Voorburgwal", + "id": "adr-2e8a1e522b5cacd766fbe23b58da4f8c", + "gekoppeld_perceel": [ + "ASD04-F-5658" + ], + "gemeentenaam": "Amsterdam", + "buurtcode": "BU03630104", + "wijknaam": "Burgwallen-Nieuwe Zijde", + "identificatie": "0363010000758542-0363200000218902", + "openbareruimte_id": "0363300000004690", + "waterschapsnaam": "HH Amstel, Gooi en Vecht", + "provinciecode": "PV27", + "postcode": "1012RJ", + "provincienaam": "Noord-Holland", + "geometrie_ll": "POINT(4.89108546 52.37390916)", + "centroide_ll": "POINT(4.89108546 52.37390916)", + "nummeraanduiding_id": "0363200000218902", + "waterschapscode": "31", + "adresseerbaarobject_id": "0363010000758542", + "huisnummer": 141, + "provincieafkorting": "NH", + "centroide_rd": "POINT(121215.232 487452.825)", + "geometrie_rd": "POINT(121215.232 487452.825)", + "straatnaam": "Nieuwezijds Voorburgwal", + "_version_": 1627309871430893600, + "typesortering": 4, + "sortering": 141, + "shard": "bag" + }, + { + "bron": "BAG", + "woonplaatscode": "3594", + "type": "adres", + "woonplaatsnaam": "Amsterdam", + "wijkcode": "WK036301", + "huis_nlt": "143", + "openbareruimtetype": "Weg", + "buurtnaam": "Nieuwe Kerk e.o.", + "gemeentecode": "0363", + "rdf_seealso": "http://bag.basisregistraties.overheid.nl/bag/id/nummeraanduiding/0363200012093196", + "weergavenaam": "Nieuwezijds Voorburgwal 143, 1012RJ Amsterdam", + "suggest": [ + "Nieuwezijds Voorburgwal 143, 1012RJ Amsterdam", + "Nieuwezijds Voorburgwal 143, 1012 RJ Amsterdam" + ], + "straatnaam_verkort": "Nieuwezijds Voorburgwal", + "id": "adr-5b6658e7817f0c7fcf29b7874b4e396c", + "gemeentenaam": "Amsterdam", + "buurtcode": "BU03630104", + "wijknaam": "Burgwallen-Nieuwe Zijde", + "identificatie": "0363200012093196-0363200012093196", + "openbareruimte_id": "0363300000004690", + "waterschapsnaam": "HH Amstel, Gooi en Vecht", + "provinciecode": "PV27", + "postcode": "1012RJ", + "provincienaam": "Noord-Holland", + "geometrie_ll": "POINT(4.89187769 52.37367138)", + "centroide_ll": "POINT(4.89187769 52.37367138)", + "nummeraanduiding_id": "0363200012093196", + "waterschapscode": "31", + "adresseerbaarobject_id": "0363200012093196", + "huisnummer": 143, + "provincieafkorting": "NH", + "centroide_rd": "POINT(121269 487426)", + "geometrie_rd": "POINT(121269 487426)", + "straatnaam": "Nieuwezijds Voorburgwal", + "_version_": 1627310104285020200, + "typesortering": 4, + "sortering": 143, + "shard": "bag" + } + ] + } +} diff --git a/test/fixtures/okf_kirstinmaki b/test/fixtures/okf_kirstinmaki deleted file mode 100644 index 79d50b963..000000000 --- a/test/fixtures/okf_kirstinmaki +++ /dev/null @@ -1,67 +0,0 @@ -{ - "status" : "OK", - "results" : [ - { - "formatted_address" : "Kirstinmäki 1, 02760 Espoo, Suomi", - "sources" : [ - { - "name" : "National Land Survey of Finland - Topographic Dataset (2013-03-08)", - "terms_of_use" : "National Land Survey open data licence - version 1.0 - 1 May 2012\nhttp://www.maanmittauslaitos.fi/en/NLS_open_data_licence_version1_20120501" - }, - { - "name" : "Itella perusosoitteisto (2014-02-01)", - "terms_of_use" : "http://www.itella.fi/liitteet/palvelutjatuotteet/yhteystietopalvelut/Postinumeropalvelut-Palvelukuvausjakayttoehdot.pdf" - } - ], - "types" : [ - "street_address" - ], - "address_components" : [ - { - "types" : [ - "street_number" - ], - "short_name" : "1", - "long_name" : "1" - }, - { - "types" : [ - "route" - ], - "short_name" : "Kirstinmäki", - "long_name" : "Kirstinmäki" - }, - { - "types" : [ - "administrative_area_level_3", - "political" - ], - "short_name" : "Espoo", - "long_name" : "Espoo" - }, - { - "types" : [ - "postal_code" - ], - "short_name" : "02760", - "long_name" : "02760" - }, - { - "types" : [ - "country", - "political" - ], - "short_name" : "FI", - "long_name" : "Suomi" - } - ], - "geometry" : { - "location" : { - "lat" : 60.2015185792087, - "lng" : 24.6667520050026 - }, - "location_type" : "RANGE_INTERPOLATED" - } - } - ] -} diff --git a/test/fixtures/okf_no_results b/test/fixtures/okf_no_results deleted file mode 100644 index 184b56dea..000000000 --- a/test/fixtures/okf_no_results +++ /dev/null @@ -1,4 +0,0 @@ -{ - "status" : "ZERO_RESULTS", - "results" : [] -} diff --git a/test/fixtures/osmnames_invalid_request b/test/fixtures/osmnames_invalid_request new file mode 100644 index 000000000..520d58af3 --- /dev/null +++ b/test/fixtures/osmnames_invalid_request @@ -0,0 +1,7 @@ +{ + "count": 20, + "startIndex": 0, + "message": "Invalid attribute value.", + "totalResults": 0, + "results": [] +} diff --git a/test/fixtures/osmnames_madison_square_garden b/test/fixtures/osmnames_madison_square_garden new file mode 100644 index 000000000..d6b7be015 --- /dev/null +++ b/test/fixtures/osmnames_madison_square_garden @@ -0,0 +1,40 @@ +{ + "count": 20, + "nextIndex": 20, + "startIndex": 0, + "totalResults": 8000, + "results": [ + { + "wikipedia": "en:New York City", + "rank": 628616.9375, + "county": "", + "street": "", + "wikidata": "Q60", + "country_code": "us", + "osm_id": "175905", + "housenumbers": "", + "id": 64, + "city": "New York City", + "display_name": "New York City, New York, United States of America", + "lon": -73.878418, + "state": "New York", + "boundingbox": [ + -74.259087, + 40.477398, + -73.70018, + 40.91618 + ], + "type": "city", + "importance": 0.782928, + "lat": 40.693073, + "class": "place", + "name": "New York City", + "country": "United States of America", + "name_suffix": "New York, US", + "osm_type": "relation", + "place_rank": 16, + "alternative_names": "New York,Nova York,Nueva York,NYC" + } + + ] +} diff --git a/test/fixtures/osmnames_no_results b/test/fixtures/osmnames_no_results new file mode 100644 index 000000000..df5cfe5db --- /dev/null +++ b/test/fixtures/osmnames_no_results @@ -0,0 +1,6 @@ +{ + "count": 20, + "startIndex": 0, + "totalResults": 0, + "results": [] +} diff --git a/test/fixtures/ovi_madison_square_garden b/test/fixtures/ovi_madison_square_garden deleted file mode 100644 index 464b8f851..000000000 --- a/test/fixtures/ovi_madison_square_garden +++ /dev/null @@ -1,72 +0,0 @@ -{ - "Response": { - "MetaInfo": { - "Timestamp": "2013-02-08T16:26:39.382+0000" - }, - "View": [ - { - "_type": "SearchResultsViewType", - "ViewId": 0, - "Result": [ - { - "Relevance": 1.0, - "MatchLevel": "houseNumber", - "MatchQuality": { - "State": 1.0, - "City": 1.0, - "Street": [ - 1.0 - ], - "HouseNumber": 1.0 - }, - "MatchType": "pointAddress", - "Location": { - "LocationId": "NT_ArsGdYbpo6dqjPQel9gTID_4", - "LocationType": "point", - "DisplayPosition": { - "Latitude": 40.7504692, - "Longitude": -73.9933777 - }, - "NavigationPosition": [ - { - "Latitude": 40.7500305, - "Longitude": -73.9942398 - } - ], - "MapView": { - "TopLeft": { - "Latitude": 40.7515934, - "Longitude": -73.9948616 - }, - "BottomRight": { - "Latitude": 40.7493451, - "Longitude": -73.9918938 - } - }, - "Address": { - "Label": "4 Penn Plz, New York, NY 10001, United States", - "Country": "USA", - "State": "NY", - "County": "New York", - "City": "New York", - "Street": "Penn Plz", - "HouseNumber": "4", - "PostalCode": "10001", - "AdditionalData": [ - { - "value": "United States", - "key": "CountryName" - }, - { - "value": "New York", - "key": "StateName" - } - ] - } - } - } - ] - } - ] - } -} diff --git a/test/fixtures/ovi_no_results b/test/fixtures/ovi_no_results deleted file mode 100644 index 26fdaf93a..000000000 --- a/test/fixtures/ovi_no_results +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Response": { - "MetaInfo": { - "Timestamp": "2013-02-08T16:41:16.723+0000" - }, - "View": [] - } -} diff --git a/test/fixtures/pointpin_10_10_10_10 b/test/fixtures/pointpin_8_8_8_8 similarity index 100% rename from test/fixtures/pointpin_10_10_10_10 rename to test/fixtures/pointpin_8_8_8_8 diff --git a/test/fixtures/postcodes_io_malvern_hills b/test/fixtures/postcodes_io_malvern_hills new file mode 100644 index 000000000..7a43cfc10 --- /dev/null +++ b/test/fixtures/postcodes_io_malvern_hills @@ -0,0 +1,36 @@ +{ + "status": 200, + "result": { + "postcode": "WR2 6NJ", + "quality": 1, + "eastings": 381676, + "northings": 259425, + "country": "England", + "nhs_ha": "West Midlands", + "longitude": -2.26972239639173, + "latitude": 52.2327158260535, + "european_electoral_region": "West Midlands", + "primary_care_trust": "Worcestershire", + "region": "West Midlands", + "lsoa": "Malvern Hills 002B", + "msoa": "Malvern Hills 002", + "incode": "6NJ", + "outcode": "WR2", + "parliamentary_constituency": "West Worcestershire", + "admin_district": "Malvern Hills", + "parish": "Hallow", + "admin_county": "Worcestershire", + "admin_ward": "Hallow", + "ccg": "NHS South Worcestershire", + "nuts": "Worcestershire", + "codes": { + "admin_district": "E07000235", + "admin_county": "E10000034", + "admin_ward": "E05007851", + "parish": "E04010305", + "parliamentary_constituency": "E14001035", + "ccg": "E38000166", + "nuts": "UKG12" + } + } +} diff --git a/test/fixtures/postcodes_io_no_results b/test/fixtures/postcodes_io_no_results new file mode 100644 index 000000000..0c929cda7 --- /dev/null +++ b/test/fixtures/postcodes_io_no_results @@ -0,0 +1,4 @@ +{ + "status": 404, + "error": "Postcode not found" +} diff --git a/test/fixtures/smarty_streets_10300 b/test/fixtures/smarty_streets_10300 new file mode 100644 index 000000000..2b5ed627d --- /dev/null +++ b/test/fixtures/smarty_streets_10300 @@ -0,0 +1 @@ +{"input_index":0, "status":"invalid_zipcode", "reason":"Invalid ZIP Code."} diff --git a/test/fixtures/smarty_streets_13_rue_yves_toudic_75010 b/test/fixtures/smarty_streets_13_rue_yves_toudic_75010 new file mode 100644 index 000000000..9948ad473 --- /dev/null +++ b/test/fixtures/smarty_streets_13_rue_yves_toudic_75010 @@ -0,0 +1,33 @@ +[ + { + "address1": "13 Rue Yves Toudic", + "address2": "10E Arrondissement", + "address3": "75010 Paris", + "components": { + "super_administrative_area": "Ile-De-France", + "administrative_area": "Paris", + "country_iso_3": "FRA", + "locality": "Paris", + "dependent_locality": "10E Arrondissement", + "postal_code": "75010", + "postal_code_short": "75010", + "premise": "13", + "premise_number": "13", + "thoroughfare": "Rue Yves Toudic", + "thoroughfare_name": "Yves Toudic", + "thoroughfare_type": "Rue" + }, + "metadata": { + "latitude": 48.870131, + "longitude": 2.363473, + "geocode_precision": "Premise", + "max_geocode_precision": "DeliveryPoint", + "address_format": "premise thoroughfare|dependent_locality|postal_code locality" + }, + "analysis": { + "verification_status": "Verified", + "address_precision": "Premise", + "max_address_precision": "DeliveryPoint" + } + } +] diff --git a/test/fixtures/telize_10_10_10_10 b/test/fixtures/telize_10_10_10_10 deleted file mode 100644 index 700f75cc5..000000000 --- a/test/fixtures/telize_10_10_10_10 +++ /dev/null @@ -1 +0,0 @@ -{"ip":"10.10.10.10"} diff --git a/test/fixtures/telize_74_200_247_59 b/test/fixtures/telize_74_200_247_59 index a8c64d324..522e013bc 100644 --- a/test/fixtures/telize_74_200_247_59 +++ b/test/fixtures/telize_74_200_247_59 @@ -1 +1,17 @@ -{"timezone":"America\/Chicago","isp":"Layered Technologies, Inc.","region_code":"TX","country":"United States","dma_code":"0","area_code":"0","region":"Texas","ip":"74.200.247.59","asn":"AS22576","continent_code":"NA","city":"Plano","postal_code":"75093","longitude":-96.8134,"latitude":33.0347,"country_code":"US","country_code3":"USA"} +{ + "longitude": -74.0468, + "city": "Jersey City", + "timezone": "America/New_York", + "latitude": 40.7209, + "asn": 22576, + "region": "New Jersey", + "offset": -14400, + "organization": "DataPipe, Inc.", + "country_code": "US", + "ip": "74.200.247.59", + "country_code3": "USA", + "postal_code": "07302", + "continent_code": "NA", + "country": "United States", + "region_code": "NJ" +} diff --git a/test/fixtures/telize_8_8_8_8 b/test/fixtures/telize_8_8_8_8 new file mode 100644 index 000000000..e1cbeb593 --- /dev/null +++ b/test/fixtures/telize_8_8_8_8 @@ -0,0 +1 @@ +{"ip":"8.8.8.8"} diff --git a/test/fixtures/telize_no_results b/test/fixtures/telize_no_results index 700f75cc5..e1cbeb593 100644 --- a/test/fixtures/telize_no_results +++ b/test/fixtures/telize_no_results @@ -1 +1 @@ -{"ip":"10.10.10.10"} +{"ip":"8.8.8.8"} diff --git a/test/fixtures/tencent_invalid_key b/test/fixtures/tencent_invalid_key new file mode 100644 index 000000000..f5dd70fd3 --- /dev/null +++ b/test/fixtures/tencent_invalid_key @@ -0,0 +1,4 @@ +{ + "status":311, + "message":"key格式错误" +} diff --git a/test/fixtures/tencent_no_results b/test/fixtures/tencent_no_results new file mode 100644 index 000000000..178fff935 --- /dev/null +++ b/test/fixtures/tencent_no_results @@ -0,0 +1,4 @@ +{ + "status":347, + "message":"查询无结果" +} diff --git a/test/fixtures/tencent_reverse b/test/fixtures/tencent_reverse new file mode 100644 index 000000000..268376f59 --- /dev/null +++ b/test/fixtures/tencent_reverse @@ -0,0 +1,110 @@ +{ + "status":0, + "message":"query ok", + "request_id":"b8580ff8-b385-11e8-bb66-246e965de502", + "result":{ + "location":{ + "lat":31.239664, + "lng":121.499809 + }, + "address":"上海市浦东新区世纪大道1号", + "formatted_addresses":{ + "recommend":"浦东新区东方明珠广播电视塔", + "rough":"浦东新区东方明珠广播电视塔" + }, + "address_component":{ + "nation":"中国", + "province":"上海市", + "city":"上海市", + "district":"浦东新区", + "street":"世纪大道", + "street_number":"世纪大道1号" + }, + "ad_info":{ + "nation_code":"156", + "adcode":"310115", + "city_code":"156310000", + "name":"中国,上海市,上海市,浦东新区", + "location":{ + "lat":31.239664, + "lng":121.499809 + }, + "nation":"中国", + "province":"上海市", + "city":"上海市", + "district":"浦东新区" + }, + "address_reference":{ + "business_area":{ + "id":"17883725287589114835", + "title":"陆家嘴", + "location":{ + "lat":31.239664, + "lng":121.499809 + }, + "_distance":0, + "_dir_desc":"内" + }, + "famous_area":{ + "id":"17883725287589114835", + "title":"陆家嘴", + "location":{ + "lat":31.239664, + "lng":121.499809 + }, + "_distance":0, + "_dir_desc":"内" + }, + "crossroad":{ + "id":"5571681", + "title":"丰和路/明珠塔路(路口)", + "location":{ + "lat":31.23901, + "lng":121.499138 + }, + "_distance":91.4, + "_dir_desc":"东北" + }, + "town":{ + "id":"310115005", + "title":"陆家嘴街道", + "location":{ + "lat":31.239664, + "lng":121.499809 + }, + "_distance":0, + "_dir_desc":"内" + }, + "street_number":{ + "id":"15588308480676188216", + "title":"世纪大道1号", + "location":{ + "lat":31.239777, + "lng":121.49968 + }, + "_distance":17.6, + "_dir_desc":"" + }, + "street":{ + "id":"9311677944217128536", + "title":"明珠塔路", + "location":{ + "lat":31.23901, + "lng":121.499138 + }, + "_distance":91.4, + "_dir_desc":"北" + }, + "landmark_l2":{ + "id":"15588308480676188216", + "title":"东方明珠广播电视塔", + "location":{ + "lat":31.239691, + "lng":121.499718 + }, + "_distance":0, + "_dir_desc":"内" + } + } + } +} diff --git a/test/fixtures/tencent_shanghai_pearl_tower b/test/fixtures/tencent_shanghai_pearl_tower new file mode 100644 index 000000000..a4f31248b --- /dev/null +++ b/test/fixtures/tencent_shanghai_pearl_tower @@ -0,0 +1,22 @@ +{ + "status":0, + "message":"query ok", + "result":{ + "title":"东方明珠主观光层", + "location":{ + "lng":121.499809, + "lat":31.239664 + }, + "address_components":{ + "province":"上海市", + "city":"上海市", + "district":"浦东新区", + "street":"", + "street_number":"" + }, + "similarity":0.8, + "deviation":1000, + "reliability":7, + "level":11 + } +} \ No newline at end of file diff --git a/test/fixtures/uk_ordnance_survey_names_SW1A1AA b/test/fixtures/uk_ordnance_survey_names_SW1A1AA new file mode 100644 index 000000000..691f09798 --- /dev/null +++ b/test/fixtures/uk_ordnance_survey_names_SW1A1AA @@ -0,0 +1,1268 @@ +{ + "header": { + "uri": "https://api.ordnancesurvey.co.uk/opennames/v1/find?query=SW1a1AA&fq=local_type%3ACity%20local_type%3AHamlet%20local_type%3AOther_Settlement%20local_type%3ATown%20local_type%3AVillage%20local_type%3APostcode", + "query": "SW1a1AA", + "format": "JSON", + "maxresults": 100, + "offset": 0, + "totalresults": 50, + "filter": "fq=local_type:City local_type:Hamlet local_type:Other_Settlement local_type:Town local_type:Village local_type:Postcode" + }, + "results": [ + { + "GAZETTEER_ENTRY": { + "ID": "SW1A1AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW1A1AA", + "NAME1": "SW1A 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 529090, + "GEOMETRY_Y": 179645, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "City of Westminster", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559881", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "City of Westminster", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011164", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW111AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW111AA", + "NAME1": "SW11 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 527614, + "GEOMETRY_Y": 175543, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Battersea", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559558", + "DISTRICT_BOROUGH": "Wandsworth", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011127", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW151AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW151AA", + "NAME1": "SW15 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 523544, + "GEOMETRY_Y": 175403, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Putney", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074562835", + "DISTRICT_BOROUGH": "Wandsworth", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011127", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW161AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW161AA", + "NAME1": "SW16 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 530019, + "GEOMETRY_Y": 172701, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Streatham", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074575698", + "DISTRICT_BOROUGH": "Lambeth", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011144", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW181AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW181AA", + "NAME1": "SW18 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 526140, + "GEOMETRY_Y": 174861, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Wandsworth", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074576254", + "DISTRICT_BOROUGH": "Wandsworth", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011127", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW191AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW191AA", + "NAME1": "SW19 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 526211, + "GEOMETRY_Y": 170740, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Wimbledon", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074541243", + "DISTRICT_BOROUGH": "Merton", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010995", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW1A0AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW1A0AA", + "NAME1": "SW1A 0AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 530268, + "GEOMETRY_Y": 179545, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "City of Westminster", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559881", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "City of Westminster", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011164", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW1A1AB", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW1A1AB", + "NAME1": "SW1A 1AB", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 530240, + "GEOMETRY_Y": 180708, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "City of Westminster", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559881", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "City of Westminster", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011164", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW1A1BA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW1A1BA", + "NAME1": "SW1A 1BA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 529292, + "GEOMETRY_Y": 179988, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "City of Westminster", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559881", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "City of Westminster", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011164", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW1A1DA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW1A1DA", + "NAME1": "SW1A 1DA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 529265, + "GEOMETRY_Y": 180092, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "City of Westminster", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559881", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "City of Westminster", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011164", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW1A1EA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW1A1EA", + "NAME1": "SW1A 1EA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 529340, + "GEOMETRY_Y": 180172, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "City of Westminster", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559881", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "City of Westminster", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011164", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW1A1HA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW1A1HA", + "NAME1": "SW1A 1HA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 529266, + "GEOMETRY_Y": 180304, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "City of Westminster", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559881", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "City of Westminster", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011164", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW1A1LA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW1A1LA", + "NAME1": "SW1A 1LA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 529167, + "GEOMETRY_Y": 180313, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "City of Westminster", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559881", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "City of Westminster", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011164", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW1A1RA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW1A1RA", + "NAME1": "SW1A 1RA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 529122, + "GEOMETRY_Y": 180335, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "City of Westminster", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559881", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "City of Westminster", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011164", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW1A1ZA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW1A1ZA", + "NAME1": "SW1A 1ZA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 529548, + "GEOMETRY_Y": 177433, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "London", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074813508", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "Wandsworth", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011127", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW1A2AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW1A2AA", + "NAME1": "SW1A 2AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 530047, + "GEOMETRY_Y": 179951, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "City of Westminster", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559881", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "City of Westminster", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011164", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW1P1AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW1P1AA", + "NAME1": "SW1P 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 529391, + "GEOMETRY_Y": 179143, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "City of Westminster", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559881", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "City of Westminster", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011164", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW1V1AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW1V1AA", + "NAME1": "SW1V 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 529096, + "GEOMETRY_Y": 179021, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "City of Westminster", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559881", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "City of Westminster", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011164", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "W1A1AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/W1A1AA", + "NAME1": "W1A 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 528887, + "GEOMETRY_Y": 181593, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "City of Westminster", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559881", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "City of Westminster", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011164", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "CW111AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/CW111AA", + "NAME1": "CW11 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 375892, + "GEOMETRY_Y": 360810, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Sandbach", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074576355", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "COUNTY_UNITARY": "Cheshire East", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000043553", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/UnitaryAuthority", + "REGION": "North West", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041431", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "EC1A1AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/EC1A1AA", + "NAME1": "EC1A 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 531131, + "GEOMETRY_Y": 182382, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "London", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074813508", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "Islington", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011281", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "KW151AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/KW151AA", + "NAME1": "KW15 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 344877, + "GEOMETRY_Y": 1011082, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Kirkwall", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074557613", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "COUNTY_UNITARY": "Orkney Islands", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000029961", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/UnitaryAuthority", + "REGION": "Scotland", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041429", + "COUNTRY": "Scotland", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/scotland" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "NW101AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/NW101AA", + "NAME1": "NW10 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 521839, + "GEOMETRY_Y": 185653, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "London", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074813508", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "Brent", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011447", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SA111AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SA111AA", + "NAME1": "SA11 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 275157, + "GEOMETRY_Y": 196858, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Neath / Castell-nedd", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074548341", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "COUNTY_UNITARY": "Castell-nedd Port Talbot - Neath Port Talbot", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000025498", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/UnitaryAuthority", + "REGION": "Wales", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041424", + "COUNTRY": "Wales", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/wales" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SA131AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SA131AA", + "NAME1": "SA13 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 276924, + "GEOMETRY_Y": 189650, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Port Talbot", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074549084", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "COUNTY_UNITARY": "Castell-nedd Port Talbot - Neath Port Talbot", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000025498", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/UnitaryAuthority", + "REGION": "Wales", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041424", + "COUNTRY": "Wales", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/wales" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SA151AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SA151AA", + "NAME1": "SA15 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 250541, + "GEOMETRY_Y": 200199, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Llanelli", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074571435", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "COUNTY_UNITARY": "Sir Gaerfyrddin - Carmarthenshire", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000025486", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/UnitaryAuthority", + "REGION": "Wales", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041424", + "COUNTRY": "Wales", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/wales" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SE151AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SE151AA", + "NAME1": "SE15 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 534257, + "GEOMETRY_Y": 177086, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "London", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074813508", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "Southwark", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011013", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SE171AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SE171AA", + "NAME1": "SE17 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 532610, + "GEOMETRY_Y": 178438, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "London", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074813508", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "Southwark", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011013", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SE181AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SE181AA", + "NAME1": "SE18 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 544850, + "GEOMETRY_Y": 178228, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "London", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074813508", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "Greenwich", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010777", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SE191AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SE191AA", + "NAME1": "SE19 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 533176, + "GEOMETRY_Y": 170843, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "London", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074813508", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "Lambeth", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011144", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SG111AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SG111AA", + "NAME1": "SG11 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 536285, + "GEOMETRY_Y": 218516, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "High Cross", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074574014", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#village", + "DISTRICT_BOROUGH": "East Hertfordshire", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000003679", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/District", + "COUNTY_UNITARY": "Hertfordshire", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000003909", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/County", + "REGION": "Eastern", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041425", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SG191AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SG191AA", + "NAME1": "SG19 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 517251, + "GEOMETRY_Y": 249189, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Sandy", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074570512", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "COUNTY_UNITARY": "Central Bedfordshire", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000043870", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/UnitaryAuthority", + "REGION": "Eastern", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041425", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SK101AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SK101AA", + "NAME1": "SK10 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 391487, + "GEOMETRY_Y": 373814, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Macclesfield", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074577382", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "COUNTY_UNITARY": "Cheshire East", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000043553", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/UnitaryAuthority", + "REGION": "North West", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041431", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SK121AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SK121AA", + "NAME1": "SK12 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 391902, + "GEOMETRY_Y": 383726, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Poynton", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074544996", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "COUNTY_UNITARY": "Cheshire East", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000043553", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/UnitaryAuthority", + "REGION": "North West", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041431", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SK131AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SK131AA", + "NAME1": "SK13 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 402319, + "GEOMETRY_Y": 396125, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Hadfield", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074813565", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#village", + "DISTRICT_BOROUGH": "High Peak", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000013755", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/District", + "COUNTY_UNITARY": "Derbyshire", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000013688", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/County", + "REGION": "East Midlands", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041423", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SK141AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SK141AA", + "NAME1": "SK14 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 394871, + "GEOMETRY_Y": 395016, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Hyde", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074545001", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "DISTRICT_BOROUGH": "Tameside", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000018700", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/MetropolitanDistrict", + "REGION": "North West", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041431", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SK151AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SK151AA", + "NAME1": "SK15 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 396517, + "GEOMETRY_Y": 398691, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Stalybridge", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074565101", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "DISTRICT_BOROUGH": "Tameside", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000018700", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/MetropolitanDistrict", + "REGION": "North West", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041431", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SN151AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SN151AA", + "NAME1": "SN15 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 391958, + "GEOMETRY_Y": 174073, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Chippenham", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074571472", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "COUNTY_UNITARY": "Wiltshire", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000043925", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/UnitaryAuthority", + "REGION": "South West", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041427", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SP101AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SP101AA", + "NAME1": "SP10 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 436302, + "GEOMETRY_Y": 145363, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Andover", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074567982", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "DISTRICT_BOROUGH": "Test Valley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000043511", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/District", + "COUNTY_UNITARY": "Hampshire", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000017765", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/County", + "REGION": "South East", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041421", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SS141AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SS141AA", + "NAME1": "SS14 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 570558, + "GEOMETRY_Y": 188641, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Basildon", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074573659", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "DISTRICT_BOROUGH": "Basildon", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000019739", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/District", + "COUNTY_UNITARY": "Essex", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000019687", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/County", + "REGION": "Eastern", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041425", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SS171AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SS171AA", + "NAME1": "SS17 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 569923, + "GEOMETRY_Y": 183552, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Stanford-le-Hope", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074573320", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "COUNTY_UNITARY": "Thurrock", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000038866", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/UnitaryAuthority", + "REGION": "Eastern", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041425", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "ST101AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/ST101AA", + "NAME1": "ST10 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 400909, + "GEOMETRY_Y": 343400, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Cheadle", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074560862", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "DISTRICT_BOROUGH": "Staffordshire Moorlands", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000015068", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/District", + "COUNTY_UNITARY": "Staffordshire", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000015052", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/County", + "REGION": "West Midlands", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041426", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "ST161AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/ST161AA", + "NAME1": "ST16 1AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 391804, + "GEOMETRY_Y": 322841, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Stafford", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074560217", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#town", + "DISTRICT_BOROUGH": "Stafford", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000014892", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/District", + "COUNTY_UNITARY": "Staffordshire", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000015052", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/County", + "REGION": "West Midlands", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041426", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW100AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW100AA", + "NAME1": "SW10 0AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 526506, + "GEOMETRY_Y": 176966, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "London", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074813508", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "Hammersmith and Fulham", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011259", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW101AH", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW101AH", + "NAME1": "SW10 1AH", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 526217, + "GEOMETRY_Y": 177763, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Kensington", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074558539", + "DISTRICT_BOROUGH": "Kensington and Chelsea", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011270", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW101AS", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW101AS", + "NAME1": "SW10 1AS", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 526217, + "GEOMETRY_Y": 177763, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Kensington", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074558539", + "DISTRICT_BOROUGH": "Kensington and Chelsea", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011270", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW101AW", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW101AW", + "NAME1": "SW10 1AW", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 526217, + "GEOMETRY_Y": 177763, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Kensington", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074558539", + "DISTRICT_BOROUGH": "Kensington and Chelsea", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011270", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW109AA", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW109AA", + "NAME1": "SW10 9AA", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 526000, + "GEOMETRY_Y": 177635, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "London", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074813508", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "Kensington and Chelsea", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011270", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW111AB", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW111AB", + "NAME1": "SW11 1AB", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 527614, + "GEOMETRY_Y": 175543, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "Battersea", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559558", + "DISTRICT_BOROUGH": "Wandsworth", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011127", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "SW111AD", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/postcodeunit/SW111AD", + "NAME1": "SW11 1AD", + "TYPE": "other", + "LOCAL_TYPE": "Postcode", + "GEOMETRY_X": 526994, + "GEOMETRY_Y": 175265, + "MOST_DETAIL_VIEW_RES": 3500, + "LEAST_DETAIL_VIEW_RES": 18000, + "POPULATED_PLACE": "London", + "POPULATED_PLACE_URI": "http://data.ordnancesurvey.co.uk/id/4000000074813508", + "POPULATED_PLACE_TYPE": "http://www.ordnancesurvey.co.uk/xml/codelists/localtype.xml#city", + "DISTRICT_BOROUGH": "Wandsworth", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011127", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + } + ] +} \ No newline at end of file diff --git a/test/fixtures/uk_ordnance_survey_names_london b/test/fixtures/uk_ordnance_survey_names_london new file mode 100644 index 000000000..682a90aeb --- /dev/null +++ b/test/fixtures/uk_ordnance_survey_names_london @@ -0,0 +1,3044 @@ +{ + "header": { + "uri": "https://api.ordnancesurvey.co.uk/opennames/v1/find?query=London&fq=local_type%3ACity%20local_type%3AHamlet%20local_type%3AOther_Settlement%20local_type%3ATown%20local_type%3AVillage%20local_type%3APostcode", + "query": "London", + "format": "JSON", + "maxresults": 100, + "offset": 0, + "totalresults": 211, + "filter": "fq=local_type:City local_type:Hamlet local_type:Other_Settlement local_type:Town local_type:Village local_type:Postcode" + }, + "results": [ + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074343985", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074343985", + "NAME1": "City of London", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "City", + "GEOMETRY_X": 532473, + "GEOMETRY_Y": 181219, + "MOST_DETAIL_VIEW_RES": 19000, + "LEAST_DETAIL_VIEW_RES": 9000000, + "MBR_XMIN": 530968, + "MBR_YMIN": 180398, + "MBR_XMAX": 533841, + "MBR_YMAX": 182198, + "POSTCODE_DISTRICT": "EC2V", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/EC2V", + "DISTRICT_BOROUGH": "City and County of the City of London", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011105", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2643741", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/City_of_London" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074813508", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074813508", + "NAME1": "London", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "City", + "GEOMETRY_X": 530034, + "GEOMETRY_Y": 180381, + "MOST_DETAIL_VIEW_RES": 349000, + "LEAST_DETAIL_VIEW_RES": 9000000, + "MBR_XMIN": 504454, + "MBR_YMIN": 156590, + "MBR_XMAX": 558150, + "MBR_YMAX": 200042, + "POSTCODE_DISTRICT": "WC2N", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/WC2N", + "DISTRICT_BOROUGH": "City of Westminster", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011164", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074813722", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074813722", + "NAME1": "Chelsfield", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Village", + "GEOMETRY_X": 548252, + "GEOMETRY_Y": 164175, + "MOST_DETAIL_VIEW_RES": 6000, + "LEAST_DETAIL_VIEW_RES": 250000, + "MBR_XMIN": 547768, + "MBR_YMIN": 163894, + "MBR_XMAX": 548712, + "MBR_YMAX": 164415, + "POSTCODE_DISTRICT": "BR6", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/BR6", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074576660", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074576660", + "NAME1": "Coldblow", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Village", + "GEOMETRY_X": 550399, + "GEOMETRY_Y": 173115, + "MOST_DETAIL_VIEW_RES": 5000, + "LEAST_DETAIL_VIEW_RES": 250000, + "MBR_XMIN": 549931, + "MBR_YMIN": 172851, + "MBR_XMAX": 550764, + "MBR_YMAX": 173640, + "POSTCODE_DISTRICT": "DA5", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/DA5", + "DISTRICT_BOROUGH": "Bexley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010759", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074564240", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074564240", + "NAME1": "Cudham", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Village", + "GEOMETRY_X": 544691, + "GEOMETRY_Y": 159466, + "MOST_DETAIL_VIEW_RES": 9000, + "LEAST_DETAIL_VIEW_RES": 250000, + "MBR_XMIN": 544368, + "MBR_YMIN": 158661, + "MBR_XMAX": 545149, + "MBR_YMAX": 160099, + "POSTCODE_DISTRICT": "TN14", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/TN14", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2651779", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Cudham" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074564565", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074564565", + "NAME1": "Downe", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Village", + "GEOMETRY_X": 543173, + "GEOMETRY_Y": 161647, + "MOST_DETAIL_VIEW_RES": 9000, + "LEAST_DETAIL_VIEW_RES": 250000, + "MBR_XMIN": 542664, + "MBR_YMIN": 160956, + "MBR_XMAX": 543685, + "MBR_YMAX": 162308, + "POSTCODE_DISTRICT": "BR6", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/BR6", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2651033", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Downe" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074339827", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074339827", + "NAME1": "Harefield", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Village", + "GEOMETRY_X": 505235, + "GEOMETRY_Y": 190598, + "MOST_DETAIL_VIEW_RES": 17000, + "LEAST_DETAIL_VIEW_RES": 250000, + "MBR_XMIN": 503985, + "MBR_YMIN": 189776, + "MBR_XMAX": 506559, + "MBR_YMAX": 191754, + "POSTCODE_DISTRICT": "UB9", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/UB9", + "DISTRICT_BOROUGH": "Hillingdon", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011539", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074564241", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074564241", + "NAME1": "Hazelwood", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Village", + "GEOMETRY_X": 544729, + "GEOMETRY_Y": 161589, + "MOST_DETAIL_VIEW_RES": 7000, + "LEAST_DETAIL_VIEW_RES": 250000, + "MBR_XMIN": 544293, + "MBR_YMIN": 161137, + "MBR_XMAX": 545223, + "MBR_YMAX": 162253, + "POSTCODE_DISTRICT": "TN14", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/TN14", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074549606", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074549606", + "NAME1": "Keston", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Village", + "GEOMETRY_X": 541242, + "GEOMETRY_Y": 164528, + "MOST_DETAIL_VIEW_RES": 19000, + "LEAST_DETAIL_VIEW_RES": 250000, + "MBR_XMIN": 540811, + "MBR_YMIN": 162042, + "MBR_XMAX": 542564, + "MBR_YMAX": 164993, + "POSTCODE_DISTRICT": "BR2", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/BR2", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2645758", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Keston" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074558121", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074558121", + "NAME1": "London Apprentice", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Village", + "GEOMETRY_X": 200698, + "GEOMETRY_Y": 49932, + "MOST_DETAIL_VIEW_RES": 3000, + "LEAST_DETAIL_VIEW_RES": 250000, + "MBR_XMIN": 200571, + "MBR_YMIN": 49832, + "MBR_XMAX": 201071, + "MBR_YMAX": 50332, + "POSTCODE_DISTRICT": "PL26", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/PL26", + "COUNTY_UNITARY": "Cornwall", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000043750", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/UnitaryAuthority", + "REGION": "South West", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041427", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/London_Apprentice" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074564243", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074564243", + "NAME1": "Luxted", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Village", + "GEOMETRY_X": 543324, + "GEOMETRY_Y": 160257, + "MOST_DETAIL_VIEW_RES": 5000, + "LEAST_DETAIL_VIEW_RES": 250000, + "MBR_XMIN": 542941, + "MBR_YMIN": 160071, + "MBR_XMAX": 543770, + "MBR_YMAX": 160589, + "POSTCODE_DISTRICT": "BR6", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/BR6", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074318884", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074318884", + "NAME1": "Maypole", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Village", + "GEOMETRY_X": 549164, + "GEOMETRY_Y": 163899, + "MOST_DETAIL_VIEW_RES": 4000, + "LEAST_DETAIL_VIEW_RES": 250000, + "MBR_XMIN": 548762, + "MBR_YMIN": 163576, + "MBR_XMAX": 549384, + "MBR_YMAX": 164076, + "POSTCODE_DISTRICT": "BR6", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/BR6", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074550341", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074550341", + "NAME1": "Ruxley", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Village", + "GEOMETRY_X": 547971, + "GEOMETRY_Y": 170542, + "MOST_DETAIL_VIEW_RES": 6000, + "LEAST_DETAIL_VIEW_RES": 250000, + "MBR_XMIN": 547808, + "MBR_YMIN": 170046, + "MBR_XMAX": 548734, + "MBR_YMAX": 170683, + "POSTCODE_DISTRICT": "DA14", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/DA14", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Ruxley" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074569525", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074569525", + "NAME1": "Wennington", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Village", + "GEOMETRY_X": 554128, + "GEOMETRY_Y": 180954, + "MOST_DETAIL_VIEW_RES": 7000, + "LEAST_DETAIL_VIEW_RES": 250000, + "MBR_XMIN": 553691, + "MBR_YMIN": 180709, + "MBR_XMAX": 554762, + "MBR_YMAX": 181209, + "POSTCODE_DISTRICT": "RM13", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/RM13", + "DISTRICT_BOROUGH": "Havering", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010807", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Wennington,_London" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074548838", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074548838", + "NAME1": "Bopeep", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Hamlet", + "GEOMETRY_X": 549085, + "GEOMETRY_Y": 163634, + "MOST_DETAIL_VIEW_RES": 5000, + "LEAST_DETAIL_VIEW_RES": 25000, + "MBR_XMIN": 548837, + "MBR_YMIN": 163328, + "MBR_XMAX": 549337, + "MBR_YMAX": 163828, + "POSTCODE_DISTRICT": "BR6", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/BR6", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074549966", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074549966", + "NAME1": "Hockenden", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Hamlet", + "GEOMETRY_X": 549654, + "GEOMETRY_Y": 169193, + "MOST_DETAIL_VIEW_RES": 5000, + "LEAST_DETAIL_VIEW_RES": 25000, + "MBR_XMIN": 549211, + "MBR_YMIN": 168597, + "MBR_XMAX": 549894, + "MBR_YMAX": 169266, + "POSTCODE_DISTRICT": "BR8", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/BR8", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074549232", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074549232", + "NAME1": "Kevingtown", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Hamlet", + "GEOMETRY_X": 548519, + "GEOMETRY_Y": 167454, + "MOST_DETAIL_VIEW_RES": 5000, + "LEAST_DETAIL_VIEW_RES": 25000, + "MBR_XMIN": 548316, + "MBR_YMIN": 167275, + "MBR_XMAX": 549075, + "MBR_YMAX": 168165, + "POSTCODE_DISTRICT": "BR5", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/BR5", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074541667", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074541667", + "NAME1": "Little London", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Hamlet", + "GEOMETRY_X": 568326, + "GEOMETRY_Y": 235146, + "MOST_DETAIL_VIEW_RES": 5000, + "LEAST_DETAIL_VIEW_RES": 25000, + "MBR_XMIN": 568103, + "MBR_YMIN": 234793, + "MBR_XMAX": 568603, + "MBR_YMAX": 235293, + "POSTCODE_DISTRICT": "CM7", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/CM7", + "DISTRICT_BOROUGH": "Braintree", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000019795", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/District", + "COUNTY_UNITARY": "Essex", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000019687", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/County", + "REGION": "Eastern", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041425", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074543489", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074543489", + "NAME1": "Little London", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Hamlet", + "GEOMETRY_X": 304475, + "GEOMETRY_Y": 289249, + "MOST_DETAIL_VIEW_RES": 5000, + "LEAST_DETAIL_VIEW_RES": 25000, + "MBR_XMIN": 304273, + "MBR_YMIN": 289042, + "MBR_XMAX": 304773, + "MBR_YMAX": 289542, + "POSTCODE_DISTRICT": "SY17", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SY17", + "COUNTY_UNITARY": "Powys - Powys", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000025491", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/UnitaryAuthority", + "REGION": "Wales", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041424", + "COUNTRY": "Wales", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/wales" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074570193", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074570193", + "NAME1": "Little London", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Hamlet", + "GEOMETRY_X": 547673, + "GEOMETRY_Y": 229492, + "MOST_DETAIL_VIEW_RES": 5000, + "LEAST_DETAIL_VIEW_RES": 25000, + "MBR_XMIN": 547378, + "MBR_YMIN": 229201, + "MBR_XMAX": 547878, + "MBR_YMAX": 229701, + "POSTCODE_DISTRICT": "CM23", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/CM23", + "DISTRICT_BOROUGH": "Uttlesford", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000020033", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/District", + "COUNTY_UNITARY": "Essex", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000019687", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/County", + "REGION": "Eastern", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041425", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074573567", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074573567", + "NAME1": "Little London", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Hamlet", + "GEOMETRY_X": 618547, + "GEOMETRY_Y": 323907, + "MOST_DETAIL_VIEW_RES": 5000, + "LEAST_DETAIL_VIEW_RES": 25000, + "MBR_XMIN": 618282, + "MBR_YMIN": 323706, + "MBR_XMAX": 618782, + "MBR_YMAX": 324206, + "POSTCODE_DISTRICT": "NR10", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/NR10", + "DISTRICT_BOROUGH": "Broadland", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000006553", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/District", + "COUNTY_UNITARY": "Norfolk", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000007238", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/County", + "REGION": "Eastern", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041425", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074573813", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074573813", + "NAME1": "Little London", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Hamlet", + "GEOMETRY_X": 506577, + "GEOMETRY_Y": 146740, + "MOST_DETAIL_VIEW_RES": 5000, + "LEAST_DETAIL_VIEW_RES": 25000, + "MBR_XMIN": 506255, + "MBR_YMIN": 146505, + "MBR_XMAX": 506755, + "MBR_YMAX": 147047, + "POSTCODE_DISTRICT": "GU5", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/GU5", + "DISTRICT_BOROUGH": "Guildford", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000014002", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/District", + "COUNTY_UNITARY": "Surrey", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000013965", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/County", + "REGION": "South East", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041421", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074543687", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074543687", + "NAME1": "London Beach", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Hamlet", + "GEOMETRY_X": 588416, + "GEOMETRY_Y": 136145, + "MOST_DETAIL_VIEW_RES": 5000, + "LEAST_DETAIL_VIEW_RES": 25000, + "MBR_XMIN": 588103, + "MBR_YMIN": 136037, + "MBR_XMAX": 588603, + "MBR_YMAX": 136741, + "POSTCODE_DISTRICT": "TN30", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/TN30", + "DISTRICT_BOROUGH": "Ashford", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000018232", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/District", + "COUNTY_UNITARY": "Kent", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000018210", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/County", + "REGION": "South East", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041421", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074549608", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074549608", + "NAME1": "Nash", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Hamlet", + "GEOMETRY_X": 540458, + "GEOMETRY_Y": 163928, + "MOST_DETAIL_VIEW_RES": 5000, + "LEAST_DETAIL_VIEW_RES": 25000, + "MBR_XMIN": 540112, + "MBR_YMIN": 163546, + "MBR_XMAX": 540612, + "MBR_YMAX": 164046, + "POSTCODE_DISTRICT": "BR2", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/BR2", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074561498", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074561498", + "NAME1": "Acton", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 520280, + "GEOMETRY_Y": 180066, + "MOST_DETAIL_VIEW_RES": 30000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 518934, + "MBR_YMIN": 178644, + "MBR_XMAX": 522035, + "MBR_YMAX": 183249, + "POSTCODE_DISTRICT": "W3", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/W3", + "DISTRICT_BOROUGH": "Ealing", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011399", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2657697", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Acton,_London" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074343911", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074343911", + "NAME1": "Barnet", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 526618, + "GEOMETRY_Y": 196126, + "MOST_DETAIL_VIEW_RES": 39000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 522555, + "MBR_YMIN": 193687, + "MBR_XMAX": 528620, + "MBR_YMAX": 197754, + "POSTCODE_DISTRICT": "EN4", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/EN4", + "DISTRICT_BOROUGH": "Barnet", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011378", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074559558", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559558", + "NAME1": "Battersea", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 527105, + "GEOMETRY_Y": 176161, + "MOST_DETAIL_VIEW_RES": 26000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 526180, + "MBR_YMIN": 173755, + "MBR_XMAX": 528729, + "MBR_YMAX": 177796, + "POSTCODE_DISTRICT": "SW11", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SW11", + "DISTRICT_BOROUGH": "Wandsworth", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011127", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/6690602", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Battersea" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074551459", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074551459", + "NAME1": "Beckenham", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 537449, + "GEOMETRY_Y": 169604, + "MOST_DETAIL_VIEW_RES": 34000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 534360, + "MBR_YMIN": 166461, + "MBR_XMAX": 539569, + "MBR_YMAX": 171476, + "POSTCODE_DISTRICT": "BR3", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/BR3", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2656065", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Beckenham" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074559226", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559226", + "NAME1": "Bermondsey", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 533627, + "GEOMETRY_Y": 179093, + "MOST_DETAIL_VIEW_RES": 15000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 532687, + "MBR_YMIN": 178167, + "MBR_XMAX": 534952, + "MBR_YMAX": 180499, + "POSTCODE_DISTRICT": "SE1", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SE1", + "DISTRICT_BOROUGH": "Southwark", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011013", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2655853", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Bermondsey" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074578541", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074578541", + "NAME1": "Bexley", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 549553, + "GEOMETRY_Y": 173602, + "MOST_DETAIL_VIEW_RES": 18000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 547240, + "MBR_YMIN": 172765, + "MBR_XMAX": 549960, + "MBR_YMAX": 174400, + "POSTCODE_DISTRICT": "DA5", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/DA5", + "DISTRICT_BOROUGH": "Bexley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010759", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2655775", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Bexley" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074561689", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074561689", + "NAME1": "Brentford", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 517697, + "GEOMETRY_Y": 177417, + "MOST_DETAIL_VIEW_RES": 28000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 516017, + "MBR_YMIN": 177011, + "MBR_XMAX": 520292, + "MBR_YMAX": 179637, + "POSTCODE_DISTRICT": "TW8", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/TW8", + "DISTRICT_BOROUGH": "Hounslow", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011489", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2654787", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Brentford" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074343899", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074343899", + "NAME1": "Bromley", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 540261, + "GEOMETRY_Y": 169118, + "MOST_DETAIL_VIEW_RES": 20000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 538629, + "MBR_YMIN": 167477, + "MBR_XMAX": 541185, + "MBR_YMAX": 170564, + "POSTCODE_DISTRICT": "BR1", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/BR1", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074558888", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074558888", + "NAME1": "Camberwell", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 532476, + "GEOMETRY_Y": 176980, + "MOST_DETAIL_VIEW_RES": 21000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 531872, + "MBR_YMIN": 175101, + "MBR_XMAX": 533829, + "MBR_YMAX": 178316, + "POSTCODE_DISTRICT": "SE5", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SE5", + "DISTRICT_BOROUGH": "Southwark", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011013", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/3345438", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Camberwell" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074575971", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074575971", + "NAME1": "Carshalton", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 528188, + "GEOMETRY_Y": 164544, + "MOST_DETAIL_VIEW_RES": 18000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 526585, + "MBR_YMIN": 163592, + "MBR_XMAX": 528588, + "MBR_YMAX": 166431, + "POSTCODE_DISTRICT": "SM5", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SM5", + "DISTRICT_BOROUGH": "Sutton", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010873", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2653646", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Carshalton" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074551841", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074551841", + "NAME1": "Catford", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 537693, + "GEOMETRY_Y": 173590, + "MOST_DETAIL_VIEW_RES": 24000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 536510, + "MBR_YMIN": 171977, + "MBR_XMAX": 540189, + "MBR_YMAX": 174275, + "POSTCODE_DISTRICT": "SE6", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SE6", + "DISTRICT_BOROUGH": "Lewisham", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011039", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2653516", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Catford" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074550344", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074550344", + "NAME1": "Chislehurst", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 543847, + "GEOMETRY_Y": 170855, + "MOST_DETAIL_VIEW_RES": 28000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 542569, + "MBR_YMIN": 167580, + "MBR_XMAX": 545633, + "MBR_YMAX": 171844, + "POSTCODE_DISTRICT": "BR7", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/BR7", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2653123", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Chislehurst" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074561090", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074561090", + "NAME1": "Chiswick", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 520700, + "GEOMETRY_Y": 178485, + "MOST_DETAIL_VIEW_RES": 18000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 520259, + "MBR_YMIN": 176083, + "MBR_XMAX": 522046, + "MBR_YMAX": 178809, + "POSTCODE_DISTRICT": "W4", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/W4", + "DISTRICT_BOROUGH": "Hounslow", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011489", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2653121", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Chiswick" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074559228", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559228", + "NAME1": "Clapham", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 529697, + "GEOMETRY_Y": 175442, + "MOST_DETAIL_VIEW_RES": 12000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 528519, + "MBR_YMIN": 175023, + "MBR_XMAX": 530204, + "MBR_YMAX": 176851, + "POSTCODE_DISTRICT": "SW4", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SW4", + "DISTRICT_BOROUGH": "Lambeth", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011144", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2652951", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Clapham" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074319395", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074319395", + "NAME1": "Coldharbour", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 552155, + "GEOMETRY_Y": 179050, + "MOST_DETAIL_VIEW_RES": 15000, + "LEAST_DETAIL_VIEW_RES": 25000, + "MBR_XMIN": 551806, + "MBR_YMIN": 178698, + "MBR_XMAX": 552595, + "MBR_YMAX": 179198, + "POSTCODE_DISTRICT": "RM13", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/RM13", + "DISTRICT_BOROUGH": "Havering", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010807", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Coldharbour,_Havering" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074568222", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074568222", + "NAME1": "Coulsdon", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 529832, + "GEOMETRY_Y": 159625, + "MOST_DETAIL_VIEW_RES": 32000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 528039, + "MBR_YMIN": 156590, + "MBR_XMAX": 532962, + "MBR_YMAX": 160883, + "POSTCODE_DISTRICT": "CR5", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/CR5", + "DISTRICT_BOROUGH": "Croydon", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010896", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2652249", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Coulsdon" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074568828", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074568828", + "NAME1": "Crayford", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 551362, + "GEOMETRY_Y": 174898, + "MOST_DETAIL_VIEW_RES": 23000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 549655, + "MBR_YMIN": 173735, + "MBR_XMAX": 553215, + "MBR_YMAX": 176331, + "POSTCODE_DISTRICT": "DA1", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/DA1", + "DISTRICT_BOROUGH": "Bexley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010759", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2652046", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Crayford_Manor_House_Astronomical_Society" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074575690", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074575690", + "NAME1": "Croydon", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 532327, + "GEOMETRY_Y": 165555, + "MOST_DETAIL_VIEW_RES": 30000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 531594, + "MBR_YMIN": 162408, + "MBR_XMAX": 535418, + "MBR_YMAX": 167048, + "POSTCODE_DISTRICT": "CR9", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/CR9", + "DISTRICT_BOROUGH": "Croydon", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010896", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2651817", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Croydon" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074544948", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074544948", + "NAME1": "Denham", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 523096, + "GEOMETRY_Y": 193921, + "MOST_DETAIL_VIEW_RES": 15000, + "LEAST_DETAIL_VIEW_RES": 25000, + "MBR_XMIN": 522828, + "MBR_YMIN": 193652, + "MBR_XMAX": 523328, + "MBR_YMAX": 194152, + "POSTCODE_DISTRICT": "N20", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/N20", + "DISTRICT_BOROUGH": "Barnet", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011378", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074558536", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074558536", + "NAME1": "Deptford", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 537184, + "GEOMETRY_Y": 177255, + "MOST_DETAIL_VIEW_RES": 20000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 535344, + "MBR_YMIN": 175921, + "MBR_XMAX": 537871, + "MBR_YMAX": 179015, + "POSTCODE_DISTRICT": "SE8", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SE8", + "DISTRICT_BOROUGH": "Lewisham", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011039", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2651349", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Deptford" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074343892", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074343892", + "NAME1": "Ealing", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 517868, + "GEOMETRY_Y": 180795, + "MOST_DETAIL_VIEW_RES": 33000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 515654, + "MBR_YMIN": 178370, + "MBR_XMAX": 519436, + "MBR_YMAX": 183420, + "POSTCODE_DISTRICT": "W5", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/W5", + "DISTRICT_BOROUGH": "Ealing", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011399", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074343910", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074343910", + "NAME1": "Edgware", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 519576, + "GEOMETRY_Y": 192258, + "MOST_DETAIL_VIEW_RES": 22000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 517960, + "MBR_YMIN": 191431, + "MBR_XMAX": 521413, + "MBR_YMAX": 194020, + "POSTCODE_DISTRICT": "HA8", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/HA8", + "DISTRICT_BOROUGH": "Barnet", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011378", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074343646", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074343646", + "NAME1": "Edmonton", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 534344, + "GEOMETRY_Y": 193523, + "MOST_DETAIL_VIEW_RES": 30000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 531844, + "MBR_YMIN": 191461, + "MBR_XMAX": 536408, + "MBR_YMAX": 195641, + "POSTCODE_DISTRICT": "N9", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/N9", + "DISTRICT_BOROUGH": "Enfield", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011329", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2650209", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Edmonton,_London" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074551840", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074551840", + "NAME1": "Eltham", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 543047, + "GEOMETRY_Y": 174425, + "MOST_DETAIL_VIEW_RES": 32000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 540270, + "MBR_YMIN": 171432, + "MBR_XMAX": 545189, + "MBR_YMAX": 176334, + "POSTCODE_DISTRICT": "SE9", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SE9", + "DISTRICT_BOROUGH": "Greenwich", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010777", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2650042", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Eltham" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074343645", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074343645", + "NAME1": "Enfield", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 532620, + "GEOMETRY_Y": 196563, + "MOST_DETAIL_VIEW_RES": 43000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 530532, + "MBR_YMIN": 195470, + "MBR_XMAX": 537168, + "MBR_YMAX": 199940, + "POSTCODE_DISTRICT": "EN2", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/EN2", + "DISTRICT_BOROUGH": "Enfield", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011329", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074569176", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074569176", + "NAME1": "Erith", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 551421, + "GEOMETRY_Y": 178014, + "MOST_DETAIL_VIEW_RES": 24000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 548915, + "MBR_YMIN": 176838, + "MBR_XMAX": 552664, + "MBR_YMAX": 180003, + "POSTCODE_DISTRICT": "DA8", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/DA8", + "DISTRICT_BOROUGH": "Bexley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010759", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2649937", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Erith" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074549619", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074549619", + "NAME1": "Feltham", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 510632, + "GEOMETRY_Y": 173185, + "MOST_DETAIL_VIEW_RES": 28000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 508526, + "MBR_YMIN": 171139, + "MBR_XMAX": 512005, + "MBR_YMAX": 175516, + "POSTCODE_DISTRICT": "TW13", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/TW13", + "DISTRICT_BOROUGH": "Hounslow", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011489", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2649571", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Feltham" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074576629", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074576629", + "NAME1": "Finchley", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 525120, + "GEOMETRY_Y": 190603, + "MOST_DETAIL_VIEW_RES": 39000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 523961, + "MBR_YMIN": 187182, + "MBR_XMAX": 527869, + "MBR_YMAX": 193189, + "POSTCODE_DISTRICT": "N3", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/N3", + "DISTRICT_BOROUGH": "Barnet", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011378", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2649441", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Finchley" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074563040", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074563040", + "NAME1": "Greenford", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 514396, + "GEOMETRY_Y": 182238, + "MOST_DETAIL_VIEW_RES": 30000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 513320, + "MBR_YMIN": 181077, + "MBR_XMAX": 516640, + "MBR_YMAX": 185655, + "POSTCODE_DISTRICT": "UB6", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/UB6", + "DISTRICT_BOROUGH": "Ealing", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011399", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2647972", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Greenford" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074578783", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074578783", + "NAME1": "Greenwich", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 538233, + "GEOMETRY_Y": 177402, + "MOST_DETAIL_VIEW_RES": 28000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 537411, + "MBR_YMIN": 176207, + "MBR_XMAX": 540362, + "MBR_YMAX": 180547, + "POSTCODE_DISTRICT": "SE10", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SE10", + "DISTRICT_BOROUGH": "Greenwich", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010777", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2647937", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Greenwich" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074559563", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559563", + "NAME1": "Hackney", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 534945, + "GEOMETRY_Y": 184665, + "MOST_DETAIL_VIEW_RES": 22000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 534277, + "MBR_YMIN": 183208, + "MBR_XMAX": 537651, + "MBR_YMAX": 185500, + "POSTCODE_DISTRICT": "E8", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/E8", + "DISTRICT_BOROUGH": "Hackney", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011199", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2647694", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Hackney_Central" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074541613", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074541613", + "NAME1": "Hampstead", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 526369, + "GEOMETRY_Y": 185770, + "MOST_DETAIL_VIEW_RES": 42000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 523942, + "MBR_YMIN": 183293, + "MBR_XMAX": 528194, + "MBR_YMAX": 189735, + "POSTCODE_DISTRICT": "NW3", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/NW3", + "DISTRICT_BOROUGH": "Camden", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011244", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2647553", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Hampstead" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074552296", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074552296", + "NAME1": "Harrow", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 515179, + "GEOMETRY_Y": 187073, + "MOST_DETAIL_VIEW_RES": 30000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 512092, + "MBR_YMIN": 185031, + "MBR_XMAX": 516724, + "MBR_YMAX": 189636, + "POSTCODE_DISTRICT": "HA1", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/HA1", + "DISTRICT_BOROUGH": "Harrow", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011391", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2647425", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Harrow,_London" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074564185", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074564185", + "NAME1": "Hayes", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 509843, + "GEOMETRY_Y": 179876, + "MOST_DETAIL_VIEW_RES": 34000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 507650, + "MBR_YMIN": 178316, + "MBR_XMAX": 512301, + "MBR_YMAX": 183498, + "POSTCODE_DISTRICT": "UB3", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/UB3", + "DISTRICT_BOROUGH": "Hillingdon", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011539", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2647261", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Hayes,_Hillingdon" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074551186", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074551186", + "NAME1": "Hendon", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 522830, + "GEOMETRY_Y": 188571, + "MOST_DETAIL_VIEW_RES": 29000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 521684, + "MBR_YMIN": 186394, + "MBR_XMAX": 524387, + "MBR_YMAX": 190804, + "POSTCODE_DISTRICT": "NW4", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/NW4", + "DISTRICT_BOROUGH": "Barnet", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011378", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2647116", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Hendon" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074343947", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074343947", + "NAME1": "Hillingdon", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 507636, + "GEOMETRY_Y": 184701, + "MOST_DETAIL_VIEW_RES": 26000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 506253, + "MBR_YMIN": 180930, + "MBR_XMAX": 508669, + "MBR_YMAX": 184945, + "POSTCODE_DISTRICT": "UB10", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/UB10", + "DISTRICT_BOROUGH": "Hillingdon", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011539", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074574005", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074574005", + "NAME1": "Hornchurch", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 554024, + "GEOMETRY_Y": 187115, + "MOST_DETAIL_VIEW_RES": 27000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 551390, + "MBR_YMIN": 184835, + "MBR_XMAX": 555511, + "MBR_YMAX": 188205, + "POSTCODE_DISTRICT": "RM11", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/RM11", + "DISTRICT_BOROUGH": "Havering", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010807", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/6690863", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Hornchurch" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074574948", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074574948", + "NAME1": "Hornsey", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 530455, + "GEOMETRY_Y": 189324, + "MOST_DETAIL_VIEW_RES": 14000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 529382, + "MBR_YMIN": 188499, + "MBR_XMAX": 531480, + "MBR_YMAX": 189864, + "POSTCODE_DISTRICT": "N8", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/N8", + "DISTRICT_BOROUGH": "Haringey", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011290", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2646580", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Hornsey" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074561692", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074561692", + "NAME1": "Hounslow", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 513893, + "GEOMETRY_Y": 175576, + "MOST_DETAIL_VIEW_RES": 30000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 510630, + "MBR_YMIN": 173476, + "MBR_XMAX": 515250, + "MBR_YMAX": 176786, + "POSTCODE_DISTRICT": "TW3", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/TW3", + "DISTRICT_BOROUGH": "Hounslow", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011489", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2646517", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Hounslow" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074579136", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074579136", + "NAME1": "Ilford", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 543838, + "GEOMETRY_Y": 186340, + "MOST_DETAIL_VIEW_RES": 28000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 541297, + "MBR_YMIN": 185409, + "MBR_XMAX": 545634, + "MBR_YMAX": 188208, + "POSTCODE_DISTRICT": "IG1", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/IG1", + "DISTRICT_BOROUGH": "Redbridge", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010955", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2646277", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Ilford" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074561688", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074561688", + "NAME1": "Isleworth", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 516178, + "GEOMETRY_Y": 175781, + "MOST_DETAIL_VIEW_RES": 20000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 514713, + "MBR_YMIN": 174116, + "MBR_XMAX": 516939, + "MBR_YMAX": 177235, + "POSTCODE_DISTRICT": "TW7", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/TW7", + "DISTRICT_BOROUGH": "Hounslow", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011489", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2646004", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Isleworth" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074559233", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074559233", + "NAME1": "Islington", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 531671, + "GEOMETRY_Y": 183777, + "MOST_DETAIL_VIEW_RES": 17000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 530016, + "MBR_YMIN": 182917, + "MBR_XMAX": 532588, + "MBR_YMAX": 185202, + "POSTCODE_DISTRICT": "N1", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/N1", + "DISTRICT_BOROUGH": "Islington", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011281", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2646003", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Islington" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074551926", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074551926", + "NAME1": "Kenton", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 516760, + "GEOMETRY_Y": 188419, + "MOST_DETAIL_VIEW_RES": 21000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 515901, + "MBR_YMIN": 187416, + "MBR_XMAX": 519146, + "MBR_YMAX": 190158, + "POSTCODE_DISTRICT": "HA3", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/HA3", + "DISTRICT_BOROUGH": "Brent", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011447", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2645788", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Kenton" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074578779", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074578779", + "NAME1": "Lewisham", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 538098, + "GEOMETRY_Y": 174995, + "MOST_DETAIL_VIEW_RES": 14000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 537360, + "MBR_YMIN": 174154, + "MBR_XMAX": 539149, + "MBR_YMAX": 176323, + "POSTCODE_DISTRICT": "SE13", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SE13", + "DISTRICT_BOROUGH": "Lewisham", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011039", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2644556", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Lewisham" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074575394", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074575394", + "NAME1": "Merton", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 526411, + "GEOMETRY_Y": 169885, + "MOST_DETAIL_VIEW_RES": 11000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 525130, + "MBR_YMIN": 168745, + "MBR_XMAX": 526769, + "MBR_YMAX": 170193, + "POSTCODE_DISTRICT": "SW19", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SW19", + "DISTRICT_BOROUGH": "Merton", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010995", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074575392", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074575392", + "NAME1": "Mitcham", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 527355, + "GEOMETRY_Y": 168640, + "MOST_DETAIL_VIEW_RES": 29000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 526118, + "MBR_YMIN": 166836, + "MBR_XMAX": 530598, + "MBR_YMAX": 170915, + "POSTCODE_DISTRICT": "CR4", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/CR4", + "DISTRICT_BOROUGH": "Merton", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010995", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2642414", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Mitcham" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074343979", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074343979", + "NAME1": "Morden", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 525817, + "GEOMETRY_Y": 168499, + "MOST_DETAIL_VIEW_RES": 28000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 523269, + "MBR_YMIN": 165940, + "MBR_XMAX": 527544, + "MBR_YMAX": 169002, + "POSTCODE_DISTRICT": "SM4", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SM4", + "DISTRICT_BOROUGH": "Merton", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010995", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074563041", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074563041", + "NAME1": "Northolt", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 513071, + "GEOMETRY_Y": 184287, + "MOST_DETAIL_VIEW_RES": 24000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 511198, + "MBR_YMIN": 182348, + "MBR_XMAX": 514844, + "MBR_YMAX": 185827, + "POSTCODE_DISTRICT": "UB5", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/UB5", + "DISTRICT_BOROUGH": "Ealing", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011399", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2641290", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Northolt" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074541727", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074541727", + "NAME1": "Northwood", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 509249, + "GEOMETRY_Y": 191464, + "MOST_DETAIL_VIEW_RES": 21000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 507333, + "MBR_YMIN": 190307, + "MBR_XMAX": 510504, + "MBR_YMAX": 192389, + "POSTCODE_DISTRICT": "HA6", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/HA6", + "DISTRICT_BOROUGH": "Hillingdon", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011539", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2641216", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Northwood,_London" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074549229", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074549229", + "NAME1": "Orpington", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 546204, + "GEOMETRY_Y": 166159, + "MOST_DETAIL_VIEW_RES": 42000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 544022, + "MBR_YMIN": 164211, + "MBR_XMAX": 548159, + "MBR_YMAX": 170604, + "POSTCODE_DISTRICT": "BR6", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/BR6", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2640894", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Orpington" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074576542", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074576542", + "NAME1": "Penge", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 535429, + "GEOMETRY_Y": 170332, + "MOST_DETAIL_VIEW_RES": 16000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 533470, + "MBR_YMIN": 169374, + "MBR_XMAX": 535926, + "MBR_YMAX": 171459, + "POSTCODE_DISTRICT": "SE20", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SE20", + "DISTRICT_BOROUGH": "Bromley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010772", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/6941038", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Penge" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074560966", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074560966", + "NAME1": "Pinner", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 512165, + "GEOMETRY_Y": 189570, + "MOST_DETAIL_VIEW_RES": 27000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 510581, + "MBR_YMIN": 187553, + "MBR_XMAX": 513449, + "MBR_YMAX": 191749, + "POSTCODE_DISTRICT": "HA5", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/HA5", + "DISTRICT_BOROUGH": "Harrow", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011391", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2640275", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Pinner" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074567896", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074567896", + "NAME1": "Purley", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 531267, + "GEOMETRY_Y": 161623, + "MOST_DETAIL_VIEW_RES": 22000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 528988, + "MBR_YMIN": 160000, + "MBR_XMAX": 532394, + "MBR_YMAX": 162577, + "POSTCODE_DISTRICT": "CR8", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/CR8", + "DISTRICT_BOROUGH": "Croydon", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010896", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2639842", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Purley,_London" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074562835", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074562835", + "NAME1": "Putney", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 523957, + "GEOMETRY_Y": 175039, + "MOST_DETAIL_VIEW_RES": 25000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 522538, + "MBR_YMIN": 172558, + "MBR_XMAX": 524467, + "MBR_YMAX": 176357, + "POSTCODE_DISTRICT": "SW15", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SW15", + "DISTRICT_BOROUGH": "Wandsworth", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011127", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2639835", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Putney" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074569858", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074569858", + "NAME1": "Rainham", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 552037, + "GEOMETRY_Y": 182247, + "MOST_DETAIL_VIEW_RES": 24000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 550509, + "MBR_YMIN": 180570, + "MBR_XMAX": 554151, + "MBR_YMAX": 183556, + "POSTCODE_DISTRICT": "RM13", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/RM13", + "DISTRICT_BOROUGH": "Havering", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010807", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2639690", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Rainham,_London" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074569531", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074569531", + "NAME1": "Romford", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 551490, + "GEOMETRY_Y": 189133, + "MOST_DETAIL_VIEW_RES": 33000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 548866, + "MBR_YMIN": 186414, + "MBR_XMAX": 553933, + "MBR_YMAX": 190964, + "POSTCODE_DISTRICT": "RM1", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/RM1", + "DISTRICT_BOROUGH": "Havering", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010807", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2639192", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Romford" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074561171", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074561171", + "NAME1": "Ruislip", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 509092, + "GEOMETRY_Y": 187621, + "MOST_DETAIL_VIEW_RES": 48000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 507725, + "MBR_YMIN": 183907, + "MBR_XMAX": 512566, + "MBR_YMAX": 191288, + "POSTCODE_DISTRICT": "HA4", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/HA4", + "DISTRICT_BOROUGH": "Hillingdon", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011539", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2638976", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Ruislip" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074550722", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074550722", + "NAME1": "Sidcup", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 546204, + "GEOMETRY_Y": 172826, + "MOST_DETAIL_VIEW_RES": 26000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 544527, + "MBR_YMIN": 170403, + "MBR_XMAX": 548484, + "MBR_YMAX": 174213, + "POSTCODE_DISTRICT": "DA15", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/DA15", + "DISTRICT_BOROUGH": "Bexley", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010759", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2637861", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Sidcup" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074562074", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074562074", + "NAME1": "Southall", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 512825, + "GEOMETRY_Y": 180394, + "MOST_DETAIL_VIEW_RES": 33000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 510521, + "MBR_YMIN": 178552, + "MBR_XMAX": 515617, + "MBR_YMAX": 182802, + "POSTCODE_DISTRICT": "UB1", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/UB1", + "DISTRICT_BOROUGH": "Ealing", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011399", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2637490", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Southall" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074577371", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074577371", + "NAME1": "Southgate", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 529680, + "GEOMETRY_Y": 193962, + "MOST_DETAIL_VIEW_RES": 26000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 528124, + "MBR_YMIN": 191777, + "MBR_XMAX": 531086, + "MBR_YMAX": 195820, + "POSTCODE_DISTRICT": "N14", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/N14", + "DISTRICT_BOROUGH": "Enfield", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011329", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Southgate,_London" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074343954", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074343954", + "NAME1": "Southwark", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 532192, + "GEOMETRY_Y": 179919, + "MOST_DETAIL_VIEW_RES": 13000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 531188, + "MBR_YMIN": 178875, + "MBR_XMAX": 533116, + "MBR_YMAX": 180691, + "POSTCODE_DISTRICT": "SE1", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SE1", + "DISTRICT_BOROUGH": "Southwark", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011013", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074553072", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074553072", + "NAME1": "Stanmore", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 517015, + "GEOMETRY_Y": 192329, + "MOST_DETAIL_VIEW_RES": 35000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 514520, + "MBR_YMIN": 190003, + "MBR_XMAX": 519942, + "MBR_YMAX": 194396, + "POSTCODE_DISTRICT": "HA7", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/HA7", + "DISTRICT_BOROUGH": "Harrow", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011391", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2637063", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Stanmore" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074579133", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074579133", + "NAME1": "Stratford", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 538840, + "GEOMETRY_Y": 184272, + "MOST_DETAIL_VIEW_RES": 18000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 537329, + "MBR_YMIN": 182798, + "MBR_XMAX": 539561, + "MBR_YMAX": 185588, + "POSTCODE_DISTRICT": "E15", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/E15", + "DISTRICT_BOROUGH": "Newham", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010929", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2636714", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Stratford,_London" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074575698", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074575698", + "NAME1": "Streatham", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 530139, + "GEOMETRY_Y": 171999, + "MOST_DETAIL_VIEW_RES": 28000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 528804, + "MBR_YMIN": 169624, + "MBR_XMAX": 531437, + "MBR_YMAX": 173994, + "POSTCODE_DISTRICT": "SW16", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SW16", + "DISTRICT_BOROUGH": "Lambeth", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011144", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2636675", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Streatham" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074343897", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074343897", + "NAME1": "Sutton", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 525864, + "GEOMETRY_Y": 164316, + "MOST_DETAIL_VIEW_RES": 30000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 524772, + "MBR_YMIN": 162055, + "MBR_XMAX": 526782, + "MBR_YMAX": 166640, + "POSTCODE_DISTRICT": "SM1", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SM1", + "DISTRICT_BOROUGH": "Sutton", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010873", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074574409", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074574409", + "NAME1": "Tottenham", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 533604, + "GEOMETRY_Y": 189510, + "MOST_DETAIL_VIEW_RES": 26000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 531480, + "MBR_YMIN": 187950, + "MBR_XMAX": 535529, + "MBR_YMAX": 191793, + "POSTCODE_DISTRICT": "N15", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/N15", + "DISTRICT_BOROUGH": "Haringey", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011290", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2635608", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Tottenham" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074573321", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074573321", + "NAME1": "Upminster", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 556014, + "GEOMETRY_Y": 186548, + "MOST_DETAIL_VIEW_RES": 22000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 554855, + "MBR_YMIN": 185391, + "MBR_XMAX": 557248, + "MBR_YMAX": 188816, + "POSTCODE_DISTRICT": "RM14", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/RM14", + "DISTRICT_BOROUGH": "Havering", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010807", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2635150", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Upminster" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074565718", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074565718", + "NAME1": "Uxbridge", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 505528, + "GEOMETRY_Y": 184129, + "MOST_DETAIL_VIEW_RES": 21000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 504454, + "MBR_YMIN": 182376, + "MBR_XMAX": 506893, + "MBR_YMAX": 185632, + "POSTCODE_DISTRICT": "UB8", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/UB8", + "DISTRICT_BOROUGH": "Hillingdon", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011539", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2635042", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Uxbridge" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074575967", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074575967", + "NAME1": "Wallington", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 528955, + "GEOMETRY_Y": 163652, + "MOST_DETAIL_VIEW_RES": 20000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 528184, + "MBR_YMIN": 162582, + "MBR_XMAX": 529792, + "MBR_YMAX": 165683, + "POSTCODE_DISTRICT": "SM6", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SM6", + "DISTRICT_BOROUGH": "Sutton", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010873", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2634867", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Wallington,_London" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074576254", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074576254", + "NAME1": "Wandsworth", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 525661, + "GEOMETRY_Y": 174637, + "MOST_DETAIL_VIEW_RES": 20000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 524273, + "MBR_YMIN": 172891, + "MBR_XMAX": 527413, + "MBR_YMAX": 175697, + "POSTCODE_DISTRICT": "SW18", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SW18", + "DISTRICT_BOROUGH": "Wandsworth", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011127", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2634812", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Wandsworth" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074552140", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074552140", + "NAME1": "Wanstead", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 540447, + "GEOMETRY_Y": 188594, + "MOST_DETAIL_VIEW_RES": 18000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 539909, + "MBR_YMIN": 187206, + "MBR_XMAX": 541420, + "MBR_YMAX": 189925, + "POSTCODE_DISTRICT": "E11", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/E11", + "DISTRICT_BOROUGH": "Redbridge", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010955", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2634803", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Wanstead" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074563042", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074563042", + "NAME1": "Wembley", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 518419, + "GEOMETRY_Y": 185248, + "MOST_DETAIL_VIEW_RES": 30000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 516053, + "MBR_YMIN": 184329, + "MBR_XMAX": 520606, + "MBR_YMAX": 187949, + "POSTCODE_DISTRICT": "HA9", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/HA9", + "DISTRICT_BOROUGH": "Brent", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011447", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2634549", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Wembley" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074562838", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074562838", + "NAME1": "Willesden", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 522522, + "GEOMETRY_Y": 184646, + "MOST_DETAIL_VIEW_RES": 20000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 521403, + "MBR_YMIN": 183086, + "MBR_XMAX": 523646, + "MBR_YMAX": 186103, + "POSTCODE_DISTRICT": "NW10", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/NW10", + "DISTRICT_BOROUGH": "Brent", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000011447", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2633907", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Willesden" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074541243", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074541243", + "NAME1": "Wimbledon", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 524915, + "GEOMETRY_Y": 170559, + "MOST_DETAIL_VIEW_RES": 35000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 521440, + "MBR_YMIN": 169313, + "MBR_XMAX": 526763, + "MBR_YMAX": 174009, + "POSTCODE_DISTRICT": "SW19", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SW19", + "DISTRICT_BOROUGH": "Merton", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010995", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2633866", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Wimbledon,_London" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074343914", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074343914", + "NAME1": "Woodford", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 540921, + "GEOMETRY_Y": 191835, + "MOST_DETAIL_VIEW_RES": 30000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 539151, + "MBR_YMIN": 189582, + "MBR_XMAX": 543060, + "MBR_YMAX": 194179, + "POSTCODE_DISTRICT": "IG8", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/IG8", + "DISTRICT_BOROUGH": "Redbridge", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010955", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england" + } + }, + { + "GAZETTEER_ENTRY": { + "ID": "osgb4000000074578663", + "NAMES_URI": "http://data.ordnancesurvey.co.uk/id/4000000074578663", + "NAME1": "Woolwich", + "TYPE": "populatedPlace", + "LOCAL_TYPE": "Other Settlement", + "GEOMETRY_X": 543354, + "GEOMETRY_Y": 178854, + "MOST_DETAIL_VIEW_RES": 21000, + "LEAST_DETAIL_VIEW_RES": 60000, + "MBR_XMIN": 541660, + "MBR_YMIN": 177231, + "MBR_XMAX": 544364, + "MBR_YMAX": 180531, + "POSTCODE_DISTRICT": "SE18", + "POSTCODE_DISTRICT_URI": "http://data.ordnancesurvey.co.uk/id/postcodedistrict/SE18", + "DISTRICT_BOROUGH": "Greenwich", + "DISTRICT_BOROUGH_URI": "http://data.ordnancesurvey.co.uk/id/7000000000010777", + "DISTRICT_BOROUGH_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/LondonBorough", + "COUNTY_UNITARY": "Greater London", + "COUNTY_UNITARY_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041441", + "COUNTY_UNITARY_TYPE": "http://data.ordnancesurvey.co.uk/ontology/admingeo/GreaterLondonAuthority", + "REGION": "London", + "REGION_URI": "http://data.ordnancesurvey.co.uk/id/7000000000041428", + "COUNTRY": "England", + "COUNTRY_URI": "http://data.ordnancesurvey.co.uk/id/country/england", + "SAME_AS_GEONAMES": "http://sws.geonames.org/2633583", + "SAME_AS_DBPEDIA": "http://dbpedia.org/resource/Woolwich" + } + } + ] +} \ No newline at end of file diff --git a/test/fixtures/uk_ordnance_survey_names_no_results b/test/fixtures/uk_ordnance_survey_names_no_results new file mode 100644 index 000000000..ed4ad4136 --- /dev/null +++ b/test/fixtures/uk_ordnance_survey_names_no_results @@ -0,0 +1,11 @@ +{ + "header": { + "uri": "https://api.ordnancesurvey.co.uk/opennames/v1/find?query=sxz%60x%60zx%60xz%60xz%60&fq=local_type%3ACity%20local_type%3AHamlet%20local_type%3AOther_Settlement%20local_type%3ATown%20local_type%3AVillage%20local_type%3APostcode", + "query": "sxz`x`zx`xz`xz`", + "format": "JSON", + "maxresults": 100, + "offset": 0, + "totalresults": 0, + "filter": "fq=local_type:City local_type:Hamlet local_type:Other_Settlement local_type:Town local_type:Village local_type:Postcode" + } +} \ No newline at end of file diff --git a/test/fixtures/yandex_kremlin b/test/fixtures/yandex_kremlin index f08b6ea3a..77ac19451 100644 --- a/test/fixtures/yandex_kremlin +++ b/test/fixtures/yandex_kremlin @@ -1,48 +1,79 @@ { - "response": { - "GeoObjectCollection": { + "response": { + "GeoObjectCollection": { + "metaDataProperty": { + "GeocoderResponseMetaData": { + "request": "Kremlin, Moscow, Russia", + "found": "8", + "results": "10" + } + }, + "featureMember": [ + { + "GeoObject": { "metaDataProperty": { - "GeocoderResponseMetaData": { - "request": "Кремль, Moscow, Russia", - "found": "1", - "results": "10" - } - }, - "featureMember": [ - { - "GeoObject": { - "metaDataProperty": { - "GeocoderMetaData": { - "kind": "vegetation", - "text": "Россия, Москва, Московский Кремль", - "precision": "other", - "AddressDetails": { - "Country": { - "CountryNameCode": "RU", - "CountryName": "Россия", - "Locality": { - "LocalityName": "Москва", - "Premise": { - "PremiseName": "Московский Кремль" - } - } - } - } - } - }, - "name": "Московский Кремль", - "boundedBy": { - "Envelope": { - "lowerCorner": "37.584182 55.733361", - "upperCorner": "37.650064 55.770517" - } - }, - "Point": { - "pos": "37.617123 55.751943" + "GeocoderMetaData": { + "kind": "district", + "text": "Russia, Moscow, Moscow Kremlin", + "precision": "other", + "Address": { + "country_code": "RU", + "formatted": "Moscow, Moscow Kremlin", + "Components": [ + { + "kind": "country", + "name": "Russia" + }, + { + "kind": "province", + "name": "Tsentralny federalny okrug" + }, + { + "kind": "province", + "name": "Moscow" + }, + { + "kind": "locality", + "name": "Moscow" + }, + { + "kind": "district", + "name": "Moscow Kremlin" + } + ] + }, + "AddressDetails": { + "Country": { + "AddressLine": "Moscow, Moscow Kremlin", + "CountryNameCode": "RU", + "CountryName": "Russia", + "AdministrativeArea": { + "AdministrativeAreaName": "Moscow", + "Locality": { + "LocalityName": "Moscow", + "DependentLocality": { + "DependentLocalityName": "Moscow Kremlin" } + } } + } } - ] + } + }, + "description": "Moscow, Russia", + "name": "Moscow Kremlin", + "boundedBy": { + "Envelope": { + "lowerCorner": "37.612587 55.748189", + "upperCorner": "37.623187 55.755044" + } + }, + "Point": { + "pos": "37.617734 55.751999" + } + } } + ] } + } } diff --git a/test/fixtures/yandex_new_york b/test/fixtures/yandex_new_york index e48bb5370..5bfa354b3 100644 --- a/test/fixtures/yandex_new_york +++ b/test/fixtures/yandex_new_york @@ -1 +1,48 @@ -{"response":{"Attribution":"","GeoObjectCollection":{"metaDataProperty":{"GeocoderResponseMetaData":{"request":"New York, NY","found":"21","results":"10"}},"featureMember":[{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"province","text":"United States, New York","precision":"other","AddressDetails":{"Country":{"AddressLine":"New York","CountryNameCode":"US","CountryName":"United States","AdministrativeArea":{"AdministrativeAreaName":"New York"}}}}},"description":"United States","name":"New York","boundedBy":{"Envelope":{"lowerCorner":"-79.762115 40.477414","upperCorner":"-71.668635 45.016078"}},"Point":{"pos":"-74.007112 40.714545"}}},{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"locality","text":"United States, New York, Bronx, New York","precision":"other","AddressDetails":{"Country":{"AddressLine":"New York, Bronx, New York","CountryNameCode":"US","CountryName":"United States","AdministrativeArea":{"AdministrativeAreaName":"New York","SubAdministrativeArea":{"SubAdministrativeAreaName":"Bronx","Locality":{"LocalityName":"New York"}}}}}}},"description":"Bronx, New York, United States","name":"New York","boundedBy":{"Envelope":{"lowerCorner":"-74.258892 40.477414","upperCorner":"-73.700373 40.917616"}},"Point":{"pos":"-74.007112 40.714545"}}},{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"hydro","text":"United States, Upper New York Bay","precision":"other","AddressDetails":{"Country":{"AddressLine":"Upper New York Bay","CountryNameCode":"US","CountryName":"United States","Locality":{"Premise":{"PremiseName":"Upper New York Bay"}}}}}},"description":"United States","name":"Upper New York Bay","boundedBy":{"Envelope":{"lowerCorner":"-74.107633 40.604124","upperCorner":"-73.998434 40.706697"}},"Point":{"pos":"-74.048758 40.660893"}}},{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"locality","text":"United States, New Jersey, Hudson, West New York","precision":"other","AddressDetails":{"Country":{"AddressLine":"New Jersey, Hudson, West New York","CountryNameCode":"US","CountryName":"United States","AdministrativeArea":{"AdministrativeAreaName":"New Jersey","SubAdministrativeArea":{"SubAdministrativeAreaName":"Hudson","Locality":{"LocalityName":"West New York"}}}}}}},"description":"Hudson, New Jersey, United States","name":"West New York","boundedBy":{"Envelope":{"lowerCorner":"-74.023569 40.7746","upperCorner":"-73.992936 40.796565"}},"Point":{"pos":"-74.015260 40.788325"}}},{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"locality","text":"United Kingdom of Great Britain and Northern Ireland, England, Lincolnshire, East Lindsey, New York","precision":"other","AddressDetails":{"Country":{"AddressLine":"England, Lincolnshire, East Lindsey, New York","CountryNameCode":"GB","CountryName":"United Kingdom of Great Britain and Northern Ireland","AdministrativeArea":{"AdministrativeAreaName":"England","SubAdministrativeArea":{"SubAdministrativeAreaName":"Lincolnshire","Locality":{"LocalityName":"New York"}}}}}}},"description":"East Lindsey, Lincolnshire, England, United Kingdom of Great Britain and Northern Ireland","name":"New York","boundedBy":{"Envelope":{"lowerCorner":"-0.205993 53.039103","upperCorner":"-0.074192 53.11847"}},"Point":{"pos":"-0.140092 53.078805"}}},{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"locality","text":"South Africa, North West, Bophirima, Naledi, New York","precision":"other","AddressDetails":{"Country":{"AddressLine":"North West, Bophirima, Naledi, New York","CountryNameCode":"ZA","CountryName":"South Africa","AdministrativeArea":{"AdministrativeAreaName":"North West","SubAdministrativeArea":{"SubAdministrativeAreaName":"Bophirima","Locality":{"LocalityName":"New York"}}}}}}},"description":"Naledi, Bophirima, North West, South Africa","name":"New York","boundedBy":{"Envelope":{"lowerCorner":"24.454037 -26.943742","upperCorner":"24.585838 -26.825556"}},"Point":{"pos":"24.519938 -26.884665"}}},{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"locality","text":"United States, New Mexico, Cibola, New York","precision":"other","AddressDetails":{"Country":{"AddressLine":"New Mexico, Cibola, New York","CountryNameCode":"US","CountryName":"United States","AdministrativeArea":{"AdministrativeAreaName":"New Mexico","SubAdministrativeArea":{"SubAdministrativeAreaName":"Cibola","Locality":{"LocalityName":"New York"}}}}}}},"description":"Cibola, New Mexico, United States","name":"New York","boundedBy":{"Envelope":{"lowerCorner":"-107.592515 35.00522","upperCorner":"-107.460714 35.113594"}},"Point":{"pos":"-107.526615 35.059425"}}},{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"locality","text":"United States, Iowa, Wayne, New York","precision":"other","AddressDetails":{"Country":{"AddressLine":"Iowa, Wayne, New York","CountryNameCode":"US","CountryName":"United States","AdministrativeArea":{"AdministrativeAreaName":"Iowa","SubAdministrativeArea":{"SubAdministrativeAreaName":"Wayne","Locality":{"LocalityName":"New York"}}}}}}},"description":"Wayne, Iowa, United States","name":"New York","boundedBy":{"Envelope":{"lowerCorner":"-93.32337 40.801487","upperCorner":"-93.191569 40.901567"}},"Point":{"pos":"-93.257469 40.851546"}}},{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"locality","text":"United States, Missouri, Caldwell, New York","precision":"other","AddressDetails":{"Country":{"AddressLine":"Missouri, Caldwell, New York","CountryNameCode":"US","CountryName":"United States","AdministrativeArea":{"AdministrativeAreaName":"Missouri","SubAdministrativeArea":{"SubAdministrativeAreaName":"Caldwell","Locality":{"LocalityName":"New York"}}}}}}},"description":"Caldwell, Missouri, United States","name":"New York","boundedBy":{"Envelope":{"lowerCorner":"-93.97525 39.633979","upperCorner":"-93.843449 39.735813"}},"Point":{"pos":"-93.909350 39.684915"}}},{"GeoObject":{"metaDataProperty":{"GeocoderMetaData":{"kind":"locality","text":"United States, Texas, Henderson, New York","precision":"other","AddressDetails":{"Country":{"AddressLine":"Texas, Henderson, New York","CountryNameCode":"US","CountryName":"United States","AdministrativeArea":{"AdministrativeAreaName":"Texas","SubAdministrativeArea":{"SubAdministrativeAreaName":"Henderson","Locality":{"LocalityName":"New York"}}}}}}},"description":"Henderson, Texas, United States","name":"New York","boundedBy":{"Envelope":{"lowerCorner":"-95.735086 32.112428","upperCorner":"-95.603285 32.224535"}},"Point":{"pos":"-95.669185 32.168499"}}}]}}} +{ + "response": { + "Attribution": "", + "GeoObjectCollection": { + "metaDataProperty": { + "GeocoderResponseMetaData": { + "request": "New York, NY", + "found": "21", + "results": "10" + } + }, + "featureMember": [ + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "province", + "text": "United States, New York", + "precision": "other", + "AddressDetails": { + "Country": { + "AddressLine": "New York", + "CountryNameCode": "US", + "CountryName": "United States", + "AdministrativeArea": { + "AdministrativeAreaName": "New York" + } + } + } + } + }, + "description": "United States", + "name": "New York", + "boundedBy": { + "Envelope": { + "lowerCorner": "-79.762115 40.477414", + "upperCorner": "-71.668635 45.016078" + } + }, + "Point": { + "pos": "-74.007112 40.714545" + } + } + } + ] + } + } +} diff --git a/test/fixtures/yandex_ontario b/test/fixtures/yandex_ontario new file mode 100644 index 000000000..478989c38 --- /dev/null +++ b/test/fixtures/yandex_ontario @@ -0,0 +1,61 @@ +{ + "response": { + "GeoObjectCollection": { + "metaDataProperty": { + "GeocoderResponseMetaData": { + "request": "ontario", + "found": "57", + "results": "10" + } + }, + "featureMember": [ + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "province", + "text": "Canada, Ontario", + "precision": "other", + "Address": { + "country_code": "CA", + "formatted": "Ontario", + "Components": [ + { + "kind": "country", + "name": "Canada" + }, + { + "kind": "province", + "name": "Ontario" + } + ] + }, + "AddressDetails": { + "Country": { + "AddressLine": "Ontario", + "CountryNameCode": "CA", + "CountryName": "Canada", + "AdministrativeArea": { + "AdministrativeAreaName": "Ontario" + } + } + } + } + }, + "description": "Canada", + "name": "Ontario", + "boundedBy": { + "Envelope": { + "lowerCorner": "-95.153382 41.704494", + "upperCorner": "-74.321387 56.88699" + } + }, + "Point": { + "pos": "-87.170557 49.294248" + } + } + } + ] + } + } +} diff --git a/test/fixtures/yandex_putilkovo_novotushinskaya_5 b/test/fixtures/yandex_putilkovo_novotushinskaya_5 new file mode 100644 index 000000000..e2626f0bd --- /dev/null +++ b/test/fixtures/yandex_putilkovo_novotushinskaya_5 @@ -0,0 +1,97 @@ +{ + "response": { + "GeoObjectCollection": { + "metaDataProperty": { + "GeocoderResponseMetaData": { + "request": "putilkovo novotushinskaya 5", + "found": "1", + "results": "10" + } + }, + "featureMember": [ + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "house", + "text": "Russia, Moscow Region, gorodskoy okrug Krasnogorsk, derevnya Putilkovo, Novotushinskaya ulitsa, 5", + "precision": "exact", + "Address": { + "country_code": "RU", + "postal_code": "143441", + "formatted": "Moscow Region, gorodskoy okrug Krasnogorsk, derevnya Putilkovo, Novotushinskaya ulitsa, 5", + "Components": [ + { + "kind": "country", + "name": "Russia" + }, + { + "kind": "province", + "name": "Tsentralny federalny okrug" + }, + { + "kind": "province", + "name": "Moscow Region" + }, + { + "kind": "area", + "name": "gorodskoy okrug Krasnogorsk" + }, + { + "kind": "locality", + "name": "derevnya Putilkovo" + }, + { + "kind": "street", + "name": "Novotushinskaya ulitsa" + }, + { + "kind": "house", + "name": "5" + } + ] + }, + "AddressDetails": { + "Country": { + "AddressLine": "Moscow Region, gorodskoy okrug Krasnogorsk, derevnya Putilkovo, Novotushinskaya ulitsa, 5", + "CountryNameCode": "RU", + "CountryName": "Russia", + "AdministrativeArea": { + "AdministrativeAreaName": "Moscow Region", + "SubAdministrativeArea": { + "SubAdministrativeAreaName": "gorodskoy okrug Krasnogorsk", + "Locality": { + "LocalityName": "derevnya Putilkovo", + "Thoroughfare": { + "ThoroughfareName": "Novotushinskaya ulitsa", + "Premise": { + "PremiseNumber": "5", + "PostalCode": { + "PostalCodeNumber": "143441" + } + } + } + } + } + } + } + } + } + }, + "description": "derevnya Putilkovo, gorodskoy okrug Krasnogorsk, Moscow Region, Russia", + "name": "Novotushinskaya ulitsa, 5", + "boundedBy": { + "Envelope": { + "lowerCorner": "37.399416 55.86995", + "upperCorner": "37.407627 55.874567" + } + }, + "Point": { + "pos": "37.403522 55.872258" + } + } + } + ] + } + } +} diff --git a/test/fixtures/yandex_volga_river b/test/fixtures/yandex_volga_river new file mode 100644 index 000000000..a314c19b1 --- /dev/null +++ b/test/fixtures/yandex_volga_river @@ -0,0 +1,63 @@ +{ + "response": { + "GeoObjectCollection": { + "metaDataProperty": { + "GeocoderResponseMetaData": { + "request": "volga river", + "found": "1", + "results": "10" + } + }, + "featureMember": [ + { + "GeoObject": { + "metaDataProperty": { + "GeocoderMetaData": { + "kind": "hydro", + "text": "Russia, Volga River", + "precision": "other", + "Address": { + "country_code": "RU", + "formatted": "Volga River", + "Components": [ + { + "kind": "country", + "name": "Russia" + }, + { + "kind": "hydro", + "name": "Volga River" + } + ] + }, + "AddressDetails": { + "Country": { + "AddressLine": "Volga River", + "CountryNameCode": "RU", + "CountryName": "Russia", + "Locality": { + "Premise": { + "PremiseName": "Volga River" + } + } + } + } + } + }, + "description": "Russia", + "name": "Volga River", + "boundedBy": { + "Envelope": { + "lowerCorner": "32.468241 45.697053", + "upperCorner": "50.181608 58.194645" + } + }, + "Point": { + "pos": "45.139984 49.550996" + } + } + } + ] + } + } +} diff --git a/test/integration/http_client_test.rb b/test/integration/http_client_test.rb deleted file mode 100644 index 21ffe5611..000000000 --- a/test/integration/http_client_test.rb +++ /dev/null @@ -1,30 +0,0 @@ -# encoding: utf-8 -require 'pathname' -require 'rubygems' -require 'test/unit' -require 'geocoder' -require 'yaml' - -class HttpClientTest < Test::Unit::TestCase - def setup - @api_keys = YAML.load_file("api_keys.yml") - end - - def test_http_basic_auth - Geocoder.configure(lookup: :geocoder_us, api_key: @api_keys["geocoder_us"]) - results = Geocoder.search "27701" - assert_not_nil results.first - end - - def test_ssl - Geocoder.configure(lookup: :esri, use_https: true) - results = Geocoder.search "27701" - assert_not_nil results.first - end - - def test_ssl_opt_out - Geocoder.configure(ip_lookup: :telize, use_https: true) - results = Geocoder.search "74.200.247.59" - assert_not_nil results.first - end -end diff --git a/test/test_helper.rb b/test/test_helper.rb index 87e11da44..43a91b9ca 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -23,7 +23,18 @@ ActiveRecord::Base.establish_connection(db_name.to_sym) ActiveRecord::Base.default_timezone = :utc - ActiveRecord::Migrator.migrate('test/db/migrate', nil) + if defined? ActiveRecord::MigrationContext + if ActiveRecord.version.release < Gem::Version.new('6.0.0') + # ActiveRecord >=5.2, takes one argument + ActiveRecord::MigrationContext.new('test/db/migrate').migrate + else + # ActiveRecord >=6.0, takes two arguments + ActiveRecord::MigrationContext.new('test/db/migrate', nil).migrate + end + else + ActiveRecord::Migrator.migrate('test/db/migrate', nil) + end + else class MysqlConnection def adapter_name @@ -217,6 +228,30 @@ def default_fixture_filename end end + require 'geocoder/lookups/ip2location' + class Ip2location + private + def default_fixture_filename + "ip2location_8_8_8_8" + end + end + + require 'geocoder/lookups/ipgeolocation' + class Ipgeolocation + private + def default_fixture_filename + "ipgeolocation_103_217_177_217" + end + end + + require 'geocoder/lookups/ipstack' + class Ipstack + private + def default_fixture_filename + "ipstack_134_201_250_155" + end + end + require 'geocoder/lookups/geoip2' class Geoip2 private @@ -286,6 +321,7 @@ def results query end end + require 'geocoder/lookups/baidu' class Baidu private @@ -294,6 +330,14 @@ def default_fixture_filename end end + require 'geocoder/lookups/nationaal_georegister_nl' + class NationaalGeoregisterNl + private + def default_fixture_filename + "nationaal_georegister_nl" + end + end + require 'geocoder/lookups/baidu_ip' class BaiduIp private @@ -302,19 +346,19 @@ def default_fixture_filename end end - require 'geocoder/lookups/geocodio' - class Geocodio + require 'geocoder/lookups/tencent' + class Tencent private def default_fixture_filename - "geocodio_1101_pennsylvania_ave" + "tencent_shanghai_pearl_tower" end end - require 'geocoder/lookups/okf' - class Okf + require 'geocoder/lookups/geocodio' + class Geocodio private def default_fixture_filename - "okf_kirstinmaki" + "geocodio_1101_pennsylvania_ave" end end @@ -330,6 +374,26 @@ def default_fixture_filename end end + require 'geocoder/lookups/postcodes_io' + class PostcodesIo + private + def fixture_prefix + 'postcodes_io' + end + + def default_fixture_filename + "#{fixture_prefix}_malvern_hills" + end + end + + require 'geocoder/lookups/uk_ordnance_survey_names' + class Geocoder::Lookup::UkOrdnanceSurveyNames + private + def default_fixture_filename + "#{fixture_prefix}_london" + end + end + require 'geocoder/lookups/geoportail_lu' class GeoportailLu private @@ -350,13 +414,6 @@ def default_fixture_filename end end - require 'geocoder/lookups/mapzen' - class Mapzen - def fixture_prefix - 'pelias' - end - end - require 'geocoder/lookups/ipinfo_io' class IpinfoIo private @@ -365,6 +422,14 @@ def default_fixture_filename end end + require 'geocoder/lookups/ipregistry' + class Ipregistry + private + def default_fixture_filename + "ipregistry_8_8_8_8" + end + end + require 'geocoder/lookups/ipapi_com' class IpapiCom private @@ -373,6 +438,14 @@ def default_fixture_filename end end + require 'geocoder/lookups/ipdata_co' + class IpdataCo + private + def default_fixture_filename + "ipdata_co_74_200_247_59" + end + end + require 'geocoder/lookups/ban_data_gouv_fr' class BanDataGouvFr private diff --git a/test/unit/error_handling_test.rb b/test/unit/error_handling_test.rb index ca20f3e5e..00066a3f5 100644 --- a/test/unit/error_handling_test.rb +++ b/test/unit/error_handling_test.rb @@ -19,7 +19,7 @@ def test_does_not_choke_on_timeout def test_always_raise_response_parse_error Geocoder.configure(:always_raise => [Geocoder::ResponseParseError]) - [:freegeoip, :google, :okf].each do |l| + [:freegeoip, :google, :ipdata_co].each do |l| lookup = Geocoder::Lookup.get(l) set_api_key!(l) assert_raises Geocoder::ResponseParseError do @@ -29,7 +29,7 @@ def test_always_raise_response_parse_error end def test_never_raise_response_parse_error - [:freegeoip, :google, :okf].each do |l| + [:freegeoip, :google, :ipdata_co].each do |l| lookup = Geocoder::Lookup.get(l) set_api_key!(l) silence_warnings do diff --git a/test/unit/geocoder_test.rb b/test/unit/geocoder_test.rb index 8dda2ba22..a371cee80 100644 --- a/test/unit/geocoder_test.rb +++ b/test/unit/geocoder_test.rb @@ -27,9 +27,9 @@ def test_geographic_center_doesnt_overwrite_argument_value def test_geocode_assigns_and_returns_coordinates v = Place.new(*geocoded_object_params(:msg)) - coords = [40.750354, -73.993371] - assert_equal coords, v.geocode - assert_equal coords, [v.latitude, v.longitude] + assert_equal [Float, Float], v.geocode.map(&:class) + assert_kind_of Numeric, v.latitude + assert_kind_of Numeric, v.longitude end def test_geocode_block_executed_when_no_results @@ -40,9 +40,8 @@ def test_geocode_block_executed_when_no_results def test_reverse_geocode_assigns_and_returns_address v = PlaceReverseGeocoded.new(*reverse_geocoded_object_params(:msg)) - address = "4 Penn Plaza, New York, NY 10001, USA" - assert_equal address, v.reverse_geocode - assert_equal address, v.address + assert_match(/New York/, v.reverse_geocode) + assert_match(/New York/, v.address) end def test_forward_and_reverse_geocoding_on_same_model_works diff --git a/test/unit/ip_address_test.rb b/test/unit/ip_address_test.rb index 0b4c3c4da..1be4c8d16 100644 --- a/test/unit/ip_address_test.rb +++ b/test/unit/ip_address_test.rb @@ -13,14 +13,42 @@ def test_valid assert !Geocoder::IpAddress.new("232.65.123").valid? assert !Geocoder::IpAddress.new("::ffff:123.456.789").valid? assert !Geocoder::IpAddress.new("Test\n232.65.123.94").valid? + assert Geocoder::IpAddress.new("[3ffe:0b00:000:0000:0001:0000:0000:000a]:80").valid? + end + + def test_internal + assert Geocoder::IpAddress.new("0.0.0.0").internal? + assert Geocoder::IpAddress.new("127.0.0.1").internal? + assert Geocoder::IpAddress.new("::1").internal? + assert Geocoder::IpAddress.new("172.19.0.1").internal? + assert Geocoder::IpAddress.new("10.100.100.1").internal? + assert Geocoder::IpAddress.new("192.168.0.1").internal? + assert !Geocoder::IpAddress.new("232.65.123.234").internal? + assert !Geocoder::IpAddress.new("127 Main St.").internal? + assert !Geocoder::IpAddress.new("John Doe\n127 Main St.\nAnywhere, USA").internal? end def test_loopback assert Geocoder::IpAddress.new("0.0.0.0").loopback? assert Geocoder::IpAddress.new("127.0.0.1").loopback? assert Geocoder::IpAddress.new("::1").loopback? + assert !Geocoder::IpAddress.new("172.19.0.1").loopback? + assert !Geocoder::IpAddress.new("10.100.100.1").loopback? + assert !Geocoder::IpAddress.new("192.168.0.1").loopback? assert !Geocoder::IpAddress.new("232.65.123.234").loopback? assert !Geocoder::IpAddress.new("127 Main St.").loopback? assert !Geocoder::IpAddress.new("John Doe\n127 Main St.\nAnywhere, USA").loopback? end + + def test_private + assert Geocoder::IpAddress.new("172.19.0.1").private? + assert Geocoder::IpAddress.new("10.100.100.1").private? + assert Geocoder::IpAddress.new("192.168.0.1").private? + assert !Geocoder::IpAddress.new("0.0.0.0").private? + assert !Geocoder::IpAddress.new("127.0.0.1").private? + assert !Geocoder::IpAddress.new("::1").private? + assert !Geocoder::IpAddress.new("232.65.123.234").private? + assert !Geocoder::IpAddress.new("127 Main St.").private? + assert !Geocoder::IpAddress.new("John Doe\n127 Main St.\nAnywhere, USA").private? + end end diff --git a/test/unit/lookup_test.rb b/test/unit/lookup_test.rb index 8dcaf8047..baaa76a9a 100644 --- a/test/unit/lookup_test.rb +++ b/test/unit/lookup_test.rb @@ -13,6 +13,7 @@ def test_responds_to_name_method def test_search_returns_empty_array_when_no_results Geocoder::Lookup.all_services_except_test.each do |l| + next if [:ipgeolocation, :nationaal_georegister_nl].include?(l) # lookups that always return a result lookup = Geocoder::Lookup.get(l) set_api_key!(l) silence_warnings do @@ -24,7 +25,7 @@ def test_search_returns_empty_array_when_no_results def test_query_url_contains_values_in_params_hash Geocoder::Lookup.all_services_except_test.each do |l| - next if [:freegeoip, :maxmind_local, :telize, :pointpin, :geoip2, :maxmind_geoip2, :mapbox, :ipinfo_io, :ipapi_com].include? l # does not use query string + next if [:freegeoip, :maxmind_local, :telize, :pointpin, :geoip2, :maxmind_geoip2, :mapbox, :ipdata_co, :ipinfo_io, :ipapi_com, :ipregistry, :ipstack, :postcodes_io, :uk_ordnance_survey_names].include? l # does not use query string set_api_key!(l) url = Geocoder::Lookup.get(l).query_url(Geocoder::Query.new( "test", :params => {:one_in_the_hand => "two in the bush"} @@ -43,7 +44,7 @@ def test_query_url_contains_values_in_params_hash :mapquest => :key, :maxmind => :l, :nominatim => :"accept-language", - :yandex => :plng + :yandex => :lang }.each do |l,p| define_method "test_passing_param_to_#{l}_query_overrides_configuration_value" do set_api_key!(l) @@ -56,10 +57,12 @@ def test_query_url_contains_values_in_params_hash end { + :bing => :language, :google => :language, :google_premier => :language, + :here => :language, :nominatim => :"accept-language", - :yandex => :plng + :yandex => :lang }.each do |l,p| define_method "test_passing_language_to_#{l}_query_overrides_configuration_value" do set_api_key!(l) @@ -144,7 +147,7 @@ def test_geocoder_ca_showpostal def test_telize_api_key Geocoder.configure(:api_key => "MY_KEY") g = Geocoder::Lookup::Telize.new - assert_match "mashape-key=MY_KEY", g.query_url(Geocoder::Query.new("232.65.123.94")) + assert_match "rapidapi-key=MY_KEY", g.query_url(Geocoder::Query.new("232.65.123.94")) end def test_ipinfo_io_api_key @@ -153,6 +156,12 @@ def test_ipinfo_io_api_key assert_match "token=MY_KEY", g.query_url(Geocoder::Query.new("232.65.123.94")) end + def test_ipregistry_api_key + Geocoder.configure(:api_key => "MY_KEY") + g = Geocoder::Lookup::Ipregistry.new + assert_match "key=MY_KEY", g.query_url(Geocoder::Query.new("232.65.123.94")) + end + def test_amap_api_key Geocoder.configure(:api_key => "MY_KEY") g = Geocoder::Lookup::Amap.new diff --git a/test/unit/lookups/ban_data_gouv_fr_test.rb b/test/unit/lookups/ban_data_gouv_fr_test.rb index 8229c9882..b7a70d518 100644 --- a/test/unit/lookups/ban_data_gouv_fr_test.rb +++ b/test/unit/lookups/ban_data_gouv_fr_test.rb @@ -14,6 +14,13 @@ def test_query_for_geocode assert_equal 'https://api-adresse.data.gouv.fr/search/?q=13+rue+yves+toudic%2C+75010+Paris', res end + def test_query_for_geocode_with_geographic_priority + query = Geocoder::Query.new('13 rue yves toudic, 75010 Paris', lat: 48.789, lon: 2.789) + lookup = Geocoder::Lookup.get(:ban_data_gouv_fr) + res = lookup.query_url(query) + assert_equal 'https://api-adresse.data.gouv.fr/search/?lat=48.789&lon=2.789&q=13+rue+yves+toudic%2C+75010+Paris', res + end + def test_query_for_reverse_geocode query = Geocoder::Query.new([48.770639, 2.364375]) lookup = Geocoder::Lookup.get(:ban_data_gouv_fr) diff --git a/test/unit/lookups/bing_test.rb b/test/unit/lookups/bing_test.rb index db9457b91..9f28c109e 100644 --- a/test/unit/lookups/bing_test.rb +++ b/test/unit/lookups/bing_test.rb @@ -42,8 +42,7 @@ def test_query_url_contains_region "manchester", :region => "uk" )) - assert_match(/Locations\/uk\?q=manchester/, url) - assert_no_match(/query/, url) + assert_match(%r!Locations/uk/\?q=manchester!, url) end def test_query_url_without_region @@ -51,28 +50,25 @@ def test_query_url_without_region url = lookup.query_url(Geocoder::Query.new( "manchester" )) - assert_match(/Locations\?q=manchester/, url) - assert_no_match(/query/, url) + assert_match(%r!Locations/\?q=manchester!, url) end - def test_query_url_contains_address_with_spaces + def test_query_url_escapes_spaces_in_address lookup = Geocoder::Lookup::Bing.new url = lookup.query_url(Geocoder::Query.new( "manchester, lancashire", :region => "uk" )) - assert_match(/Locations\/uk\?q=manchester,%20lancashire/, url) - assert_no_match(/query/, url) + assert_match(%r!Locations/uk/\?q=manchester%2C\+lancashire!, url) end - def test_query_url_contains_address_with_trailing_and_leading_spaces + def test_query_url_strips_trailing_and_leading_spaces lookup = Geocoder::Lookup::Bing.new url = lookup.query_url(Geocoder::Query.new( " manchester, lancashire ", :region => "uk" )) - assert_match(/Locations\/uk\?q=manchester,%20lancashire/, url) - assert_no_match(/query/, url) + assert_match(%r!Locations/uk/\?q=manchester%2C\+lancashire!, url) end def test_raises_exception_when_service_unavailable @@ -82,4 +78,18 @@ def test_raises_exception_when_service_unavailable l.send(:results, Geocoder::Query.new("service unavailable")) end end + + def test_raises_exception_when_bing_returns_forbidden_request + Geocoder.configure(:always_raise => [Geocoder::RequestDenied]) + assert_raises Geocoder::RequestDenied do + Geocoder.search("forbidden request") + end + end + + def test_raises_exception_when_bing_returns_internal_server_error + Geocoder.configure(:always_raise => [Geocoder::ServiceUnavailable]) + assert_raises Geocoder::ServiceUnavailable do + Geocoder.search("internal server error") + end + end end diff --git a/test/unit/lookups/esri_test.rb b/test/unit/lookups/esri_test.rb index f7d09d069..7d76457d2 100644 --- a/test/unit/lookups/esri_test.rb +++ b/test/unit/lookups/esri_test.rb @@ -24,6 +24,14 @@ def test_query_for_geocode_with_source_country assert_match %r{sourceCountry=USA}, url end + def test_query_for_geocode_with_preferred_label_values + Geocoder.configure(esri: {preferred_label_values: 'localCity'}) + query = Geocoder::Query.new("Bluffton, SC") + lookup = Geocoder::Lookup.get(:esri) + url = lookup.query_url(query) + assert_match %r{preferredLabelValues=localCity}, url + end + def test_query_for_geocode_with_token_and_for_storage token = Geocoder::EsriToken.new('xxxxx', Time.now + 60*60*24) Geocoder.configure(esri: {token: token, for_storage: true}) @@ -34,6 +42,52 @@ def test_query_for_geocode_with_token_and_for_storage assert_match %r{token=xxxxx}, url end + def test_token_from_options + options_token = Geocoder::EsriToken.new('options_token', Time.now + 60*60*24) + query = Geocoder::Query.new("Bluffton, SC", token: options_token) + lookup = Geocoder::Lookup.get(:esri) + url = lookup.query_url(query) + assert_match %r{token=options_token}, url + end + + def test_token_from_options_overrides_configuration + config_token = Geocoder::EsriToken.new('config_token', Time.now + 60*60*24) + options_token = Geocoder::EsriToken.new('options_token', Time.now + 60*60*24) + Geocoder.configure(esri: { token: config_token }) + query = Geocoder::Query.new("Bluffton, SC", token: options_token) + lookup = Geocoder::Lookup.get(:esri) + url = lookup.query_url(query) + assert_match %r{token=options_token}, url + end + + def test_query_for_geocode_with_config_for_storage_false + Geocoder.configure(esri: {for_storage: false}) + + query = Geocoder::Query.new("Bluffton, SC", for_storage: true) + lookup = Geocoder::Lookup.get(:esri) + url = lookup.query_url(query) + assert_match %r{forStorage=true}, url + + query = Geocoder::Query.new("Bluffton, SC", for_storage: false) + lookup = Geocoder::Lookup.get(:esri) + url = lookup.query_url(query) + assert_no_match %r{forStorage}, url + end + + def test_query_for_geocode_with_config_for_storage_true + Geocoder.configure(esri: {for_storage: true}) + + query = Geocoder::Query.new("Bluffton, SC", for_storage: true) + lookup = Geocoder::Lookup.get(:esri) + url = lookup.query_url(query) + assert_match %r{forStorage=true}, url + + query = Geocoder::Query.new("Bluffton, SC", for_storage: false) + lookup = Geocoder::Lookup.get(:esri) + url = lookup.query_url(query) + assert_no_match %r{forStorage}, url + end + def test_token_generation_doesnt_overwrite_existing_config Geocoder.configure(esri: {api_key: ['id','secret'], for_storage: true}) diff --git a/test/unit/lookups/freegeoip_test.rb b/test/unit/lookups/freegeoip_test.rb index 565efb6b8..1ce62b4d3 100644 --- a/test/unit/lookups/freegeoip_test.rb +++ b/test/unit/lookups/freegeoip_test.rb @@ -12,6 +12,20 @@ def test_result_on_ip_address_search assert result.is_a?(Geocoder::Result::Freegeoip) end + def test_result_on_loopback_ip_address_search + result = Geocoder.search("127.0.0.1").first + assert_equal "127.0.0.1", result.ip + assert_equal 'RD', result.country_code + assert_equal "Reserved", result.country + end + + def test_result_on_private_ip_address_search + result = Geocoder.search("172.19.0.1").first + assert_equal "172.19.0.1", result.ip + assert_equal 'RD', result.country_code + assert_equal "Reserved", result.country + end + def test_result_components result = Geocoder.search("74.200.247.59").first assert_equal "Plano, TX 75093, United States", result.address @@ -21,6 +35,6 @@ def test_host_config Geocoder.configure(freegeoip: {host: "local.com"}) lookup = Geocoder::Lookup::Freegeoip.new query = Geocoder::Query.new("24.24.24.23") - assert_match %r(http://local\.com), lookup.query_url(query) + assert_match %r(https://local\.com), lookup.query_url(query) end end diff --git a/test/unit/lookups/google_premier_test.rb b/test/unit/lookups/google_premier_test.rb index ceb5e8c6a..63ba87fd9 100644 --- a/test/unit/lookups/google_premier_test.rb +++ b/test/unit/lookups/google_premier_test.rb @@ -18,4 +18,12 @@ def test_query_url query = Geocoder::Query.new("Madison Square Garden, New York, NY") assert_equal "https://maps.googleapis.com/maps/api/geocode/json?address=Madison+Square+Garden%2C+New+York%2C+NY&channel=test-dev&client=gme-test&language=en&sensor=false&signature=doJvJqX7YJzgV9rJ0DnVkTGZqTg=", query.url end + + def test_cache_key + Geocoder.configure(google_premier: {api_key: ["deadbeef", "gme-test", "test-dev"]}) + lookup = Geocoder::Lookup.get(:google_premier) + query = Geocoder::Query.new("Madison Square Garden, New York, NY") + cache_key = lookup.send(:cache_key, query) + assert_equal "https://maps.googleapis.com/maps/api/geocode/json?address=Madison+Square+Garden%2C+New+York%2C+NY&language=en&sensor=false", cache_key + end end diff --git a/test/unit/lookups/google_test.rb b/test/unit/lookups/google_test.rb index 32f147e97..47a2b8ddf 100644 --- a/test/unit/lookups/google_test.rb +++ b/test/unit/lookups/google_test.rb @@ -3,6 +3,10 @@ class GoogleTest < GeocoderTestCase + def setup + Geocoder.configure(lookup: :google) + end + def test_google_result_components result = Geocoder.search("Madison Square Garden, New York, NY").first assert_equal "Manhattan", @@ -48,6 +52,17 @@ def test_google_viewport result.viewport end + def test_google_bounds + result = Geocoder.search("new york").first + assert_equal [40.4773991, -74.2590899, 40.9175771, -73.7002721], + result.bounds + end + + def test_google_no_bounds + result = Geocoder.search("Madison Square Garden, New York, NY").first + assert_equal nil, result.bounds + end + def test_google_query_url_contains_bounds lookup = Geocoder::Lookup::Google.new url = lookup.query_url(Geocoder::Query.new( diff --git a/test/unit/lookups/here_test.rb b/test/unit/lookups/here_test.rb index cec6bcbad..b0be288b9 100644 --- a/test/unit/lookups/here_test.rb +++ b/test/unit/lookups/here_test.rb @@ -3,16 +3,46 @@ require 'test_helper' class HereTest < GeocoderTestCase - def setup Geocoder.configure(lookup: :here) set_api_key!(:here) end def test_here_viewport - result = Geocoder.search("Madison Square Garden, New York, NY").first + result = Geocoder.search('Madison Square Garden, New York, NY').first assert_equal [40.7493451, -73.9948616, 40.7515934, -73.9918938], - result.viewport + result.viewport + end + + def test_here_query_url_contains_country + lookup = Geocoder::Lookup::Here.new + url = lookup.query_url( + Geocoder::Query.new( + 'Some Intersection', + country: 'GBR' + ) + ) + assert_match(/country=GBR/, url) end + def test_here_query_url_contains_mapview + lookup = Geocoder::Lookup::Here.new + url = lookup.query_url( + Geocoder::Query.new( + 'Some Intersection', + bounds: [[40.0, -120.0], [39.0, -121.0]] + ) + ) + assert_match(/mapview=40.0+%2C-120.0+%3B39.0+%2C-121.0+/, url) + end + + def test_here_query_url_contains_api_key + lookup = Geocoder::Lookup::Here.new + url = lookup.query_url( + Geocoder::Query.new( + 'Some Intersection' + ) + ) + assert_match(/apikey=+/, url) + end end diff --git a/test/unit/lookups/ip2location_test.rb b/test/unit/lookups/ip2location_test.rb new file mode 100644 index 000000000..6c6ad7a85 --- /dev/null +++ b/test/unit/lookups/ip2location_test.rb @@ -0,0 +1,32 @@ +# encoding: utf-8 +require 'test_helper' + +class Ip2locationTest < GeocoderTestCase + + def setup + Geocoder.configure(:ip_lookup => :ip2location) + end + + def test_ip2location_lookup_address + result = Geocoder.search("8.8.8.8").first + assert_equal "US", result.country_code + end + + def test_ip2location_lookup_loopback_address + result = Geocoder.search("127.0.0.1").first + assert_equal "INVALID IP ADDRESS", result.country_code + end + + def test_ip2location_lookup_private_address + result = Geocoder.search("172.19.0.1").first + assert_equal "INVALID IP ADDRESS", result.country_code + end + + def test_ip2location_extra_data + Geocoder.configure(:ip2location => {:package => "WS3"}) + result = Geocoder.search("8.8.8.8").first + assert_equal "United States", result.country_name + assert_equal "California", result.region_name + assert_equal "Mountain View", result.city_name + end +end diff --git a/test/unit/lookups/ipapi_com_test.rb b/test/unit/lookups/ipapi_com_test.rb index 103bbaf7c..9d35653bd 100644 --- a/test/unit/lookups/ipapi_com_test.rb +++ b/test/unit/lookups/ipapi_com_test.rb @@ -21,33 +21,43 @@ def test_result_components def test_all_api_fields result = Geocoder.search("74.200.247.59").first - assert_equal "United States", result.country - assert_equal "US", result.country_code - assert_equal "NJ", result.region - assert_equal "New Jersey", result.region_name - assert_equal "Jersey City", result.city - assert_equal "07302", result.zip - assert_equal 40.7209, result.lat - assert_equal -74.0468, result.lon - assert_equal "America/New_York", result.timezone - assert_equal "DataPipe", result.isp - assert_equal "DataPipe", result.org - assert_equal "AS22576 DataPipe, Inc.", result.as - assert_equal "", result.reverse - assert_equal false, result.mobile - assert_equal false, result.proxy - assert_equal "74.200.247.59", result.query - assert_equal "success", result.status - assert_equal nil, result.message + assert_equal("United States", result.country) + assert_equal("US", result.country_code) + assert_equal("NJ", result.region) + assert_equal("New Jersey", result.region_name) + assert_equal("Jersey City", result.city) + assert_equal("07302", result.zip) + assert_equal(40.7209, result.lat) + assert_equal(-74.0468, result.lon) + assert_equal("America/New_York", result.timezone) + assert_equal("DataPipe", result.isp) + assert_equal("DataPipe", result.org) + assert_equal("AS22576 DataPipe, Inc.", result.as) + assert_equal("", result.reverse) + assert_equal(false, result.mobile) + assert_equal(false, result.proxy) + assert_equal("74.200.247.59", result.query) + assert_equal("success", result.status) + assert_equal(nil, result.message) end - def test_localhost + def test_loopback result = Geocoder.search("::1").first + assert_equal(nil, result.lat) + assert_equal(nil, result.lon) + assert_equal([nil, nil], result.coordinates) + assert_equal(nil, result.reverse) + assert_equal("::1", result.query) + assert_equal("fail", result.status) + end + + def test_private + result = Geocoder.search("172.19.0.1").first assert_equal nil, result.lat assert_equal nil, result.lon assert_equal [nil, nil], result.coordinates assert_equal nil, result.reverse - assert_equal "::1", result.query + assert_equal "172.19.0.1", result.query assert_equal "fail", result.status end diff --git a/test/unit/lookups/ipdata_co_test.rb b/test/unit/lookups/ipdata_co_test.rb new file mode 100644 index 000000000..704783fb4 --- /dev/null +++ b/test/unit/lookups/ipdata_co_test.rb @@ -0,0 +1,68 @@ +# encoding: utf-8 +require 'test_helper' + +class IpdataCoTest < GeocoderTestCase + + def setup + Geocoder.configure(ip_lookup: :ipdata_co) + end + + def test_result_on_ip_address_search + result = Geocoder.search("74.200.247.59").first + assert result.is_a?(Geocoder::Result::IpdataCo) + end + + def test_result_on_loopback_ip_address_search + result = Geocoder.search("127.0.0.1").first + assert_equal "127.0.0.1", result.ip + assert_equal 'RD', result.country_code + assert_equal "Reserved", result.country + end + + def test_result_on_private_ip_address_search + result = Geocoder.search("172.19.0.1").first + assert_equal "172.19.0.1", result.ip + assert_equal 'RD', result.country_code + assert_equal "Reserved", result.country + end + + def test_invalid_json + Geocoder.configure(:always_raise => [Geocoder::ResponseParseError]) + assert_raise Geocoder::ResponseParseError do + Geocoder.search("8.8.8", ip_address: true) + end + end + + def test_result_components + result = Geocoder.search("74.200.247.59").first + assert_equal "Jersey City, NJ 07302, United States", result.address + end + + def test_not_authorized + Geocoder.configure(always_raise: [Geocoder::RequestDenied]) + lookup = Geocoder::Lookup.get(:ipdata_co) + assert_raises Geocoder::RequestDenied do + response = MockHttpResponse.new(code: 403) + lookup.send(:check_response_for_errors!, response) + end + end + + def test_api_key + Geocoder.configure(:api_key => 'XXXX') + + # HACK: run the code once to add the api key to the HTTP request headers + Geocoder.search('8.8.8.8') + # It's really hard to 'un-monkey-patch' the base lookup class here + + require 'webmock/test_unit' + WebMock.enable! + stubbed_request = WebMock.stub_request(:get, "https://api.ipdata.co/8.8.8.8?api-key=XXXX").to_return(status: 200) + + g = Geocoder::Lookup::IpdataCo.new + g.send(:actual_make_api_request, Geocoder::Query.new('8.8.8.8')) + assert_requested(stubbed_request) + + WebMock.reset! + WebMock.disable! + end +end diff --git a/test/unit/lookups/ipgeolocation_test.rb b/test/unit/lookups/ipgeolocation_test.rb new file mode 100644 index 000000000..880f35ec8 --- /dev/null +++ b/test/unit/lookups/ipgeolocation_test.rb @@ -0,0 +1,117 @@ +# encoding: utf-8 +require 'test_helper' + +class IpgeolocationTest < GeocoderTestCase + + def setup + Geocoder::Configuration.instance.data.clear + Geocoder::Configuration.set_defaults + Geocoder.configure( + :api_key => 'ea91e4a4159247fdb0926feae70c2911', + :ip_lookup => :ipgeolocation, + :always_raise => :all + ) + end + + def test_result_on_ip_address_search + result = Geocoder.search("103.217.177.217").first + assert result.is_a?(Geocoder::Result::Ipgeolocation) + end + + def test_result_components + result = Geocoder.search("103.217.177.217").first + assert_equal "Pakistan", result.country_name + end + + def test_all_top_level_api_fields + result = Geocoder.search("103.217.177.217").first + assert_equal "103.217.177.217", result.ip + assert_equal "AS", result.continent_code + assert_equal "Asia", result.continent_name + assert_equal "PK", result.country_code2 + assert_equal "Pakistan", result.country_name + assert_equal "Islamabad", result.city + assert_equal "44000", result.zipcode + assert_equal 33.7334, result.latitude + assert_equal 73.0785, result.longitude + end + + def test_nested_api_fields + result = Geocoder.search("103.217.177.217").first + + assert result.time_zone.is_a?(Hash) + assert_equal "Asia/Karachi", result.time_zone['name'] + + assert result.currency.is_a?(Hash) + assert_equal "PKR", result.currency['code'] + end + + def test_required_base_fields + result = Geocoder.search("103.217.177.217").first + + assert_equal "Islamabad", result.country_capital + assert_equal "Islamabad", result.state_prov + assert_equal "Islamabad", result.city + assert_equal "44000", result.zipcode + assert_equal [33.7334, 73.0785], result.coordinates + end + + def test_localhost_loopback + result = Geocoder.search("127.0.0.1").first + assert_equal "127.0.0.1", result.ip + assert_equal "RD", result.country_code2 + assert_equal "Reserved", result.country_name + end + + def test_localhost_loopback_defaults + result = Geocoder.search("127.0.0.1").first + + assert_equal "127.0.0.1", result.ip + assert_equal "", result.continent_code + assert_equal "", result.continent_name + assert_equal "RD", result.country_code2 + assert_equal "Reserved", result.country_name + assert_equal "", result.city + assert_equal "", result.zipcode + assert_equal 0, result.latitude + assert_equal 0, result.longitude + assert_equal({}, result.time_zone) + assert_equal({}, result.currency) + end + + def test_localhost_private + result = Geocoder.search("172.19.0.1").first + assert_equal "172.19.0.1", result.ip + assert_equal "RD", result.country_code2 + assert_equal "Reserved", result.country_name + end + + def test_api_request_adds_access_key + lookup = Geocoder::Lookup.get(:ipgeolocation) + assert_match(/apiKey=\w+/, lookup.query_url(Geocoder::Query.new("74.200.247.59"))) + end + + def test_api_request_adds_security_when_specified + lookup = Geocoder::Lookup.get(:ipgeolocation) + query_url = lookup.query_url(Geocoder::Query.new("74.200.247.59", params: { security: '1' })) + assert_match(/&security=1/, query_url) + end + + def test_api_request_adds_hostname_when_specified + lookup = Geocoder::Lookup.get(:ipgeolocation) + query_url = lookup.query_url(Geocoder::Query.new("74.200.247.59", params: { hostname: '1' })) + assert_match(/&hostname=1/, query_url) + end + + def test_api_request_adds_language_when_specified + lookup = Geocoder::Lookup.get(:ipgeolocation) + query_url = lookup.query_url(Geocoder::Query.new("74.200.247.59", params: { language: 'es' })) + assert_match(/&language=es/, query_url) + end + + def test_api_request_adds_fields_when_specified + lookup = Geocoder::Lookup.get(:ipgeolocation) + query_url = lookup.query_url(Geocoder::Query.new("74.200.247.59", params: { fields: 'foo,bar' })) + assert_match(/&fields=foo%2Cbar/, query_url) + end +end diff --git a/test/unit/lookups/ipinfo_io_test.rb b/test/unit/lookups/ipinfo_io_test.rb index a66093ce4..6d4335cee 100644 --- a/test/unit/lookups/ipinfo_io_test.rb +++ b/test/unit/lookups/ipinfo_io_test.rb @@ -2,27 +2,22 @@ require 'test_helper' class IpinfoIoTest < GeocoderTestCase - - def test_ipinfo_io_use_http_without_token - Geocoder.configure(:ip_lookup => :ipinfo_io, :use_https => true) - query = Geocoder::Query.new("8.8.8.8") - assert_match(/^http:/, query.url) - end - - def test_ipinfo_io_uses_https_when_auth_token_set - Geocoder.configure(:ip_lookup => :ipinfo_io, :api_key => "FOO_BAR_TOKEN", :use_https => true) - query = Geocoder::Query.new("8.8.8.8") - assert_match(/^https:/, query.url) - end - def test_ipinfo_io_lookup_loopback_address - Geocoder.configure(:ip_lookup => :ipinfo_io, :use_https => true) + Geocoder.configure(:ip_lookup => :ipinfo_io) result = Geocoder.search("127.0.0.1").first - assert_equal 0.0, result.longitude - assert_equal 0.0, result.latitude + assert_nil result.latitude + assert_nil result.longitude assert_equal "127.0.0.1", result.ip end + def test_ipinfo_io_lookup_private_address + Geocoder.configure(:ip_lookup => :ipinfo_io) + result = Geocoder.search("172.19.0.1").first + assert_nil result.latitude + assert_nil result.longitude + assert_equal "172.19.0.1", result.ip + end + def test_ipinfo_io_extra_attributes Geocoder.configure(:ip_lookup => :ipinfo_io, :use_https => true) result = Geocoder.search("8.8.8.8").first diff --git a/test/unit/lookups/ipregistry_test.rb b/test/unit/lookups/ipregistry_test.rb new file mode 100644 index 000000000..e70dc34ec --- /dev/null +++ b/test/unit/lookups/ipregistry_test.rb @@ -0,0 +1,32 @@ +# encoding: utf-8 +require 'test_helper' + +class IpregistryTest < GeocoderTestCase + def test_lookup_loopback_address + Geocoder.configure(:ip_lookup => :ipregistry) + result = Geocoder.search("127.0.0.1").first + assert_nil result.latitude + assert_nil result.longitude + assert_equal "127.0.0.1", result.ip + end + + def test_lookup_private_address + Geocoder.configure(:ip_lookup => :ipregistry) + result = Geocoder.search("172.19.0.1").first + assert_nil result.latitude + assert_nil result.longitude + assert_equal "172.19.0.1", result.ip + end + + def test_known_ip_address + Geocoder.configure(:ip_lookup => :ipregistry) + result = Geocoder.search("8.8.8.8").first + assert_equal "8.8.8.8", result.ip + assert_equal "California", result.state + assert_equal "USD", result.currency_code + assert_equal "NA", result.location_continent_code + assert_equal "US", result.location_country_code + assert_equal false, result.security_is_tor + assert_equal "America/Los_Angeles", result.time_zone_id + end +end diff --git a/test/unit/lookups/ipstack_test.rb b/test/unit/lookups/ipstack_test.rb new file mode 100644 index 000000000..455eefc15 --- /dev/null +++ b/test/unit/lookups/ipstack_test.rb @@ -0,0 +1,292 @@ +# encoding: utf-8 +require 'test_helper' + +class SpyLogger + def initialize + @log = [] + end + + def logged?(msg) + @log.include?(msg) + end + + def add(level, msg) + @log << msg + end +end + +class IpstackTest < GeocoderTestCase + + def setup + @logger = SpyLogger.new + Geocoder::Configuration.instance.data.clear + Geocoder::Configuration.set_defaults + Geocoder.configure( + :api_key => '123', + :ip_lookup => :ipstack, + :always_raise => :all, + :logger => @logger + ) + end + + def test_result_on_ip_address_search + result = Geocoder.search("134.201.250.155").first + assert result.is_a?(Geocoder::Result::Ipstack) + end + + def test_result_components + result = Geocoder.search("134.201.250.155").first + assert_equal "Los Angeles, CA 90013, United States", result.address + end + + def test_all_top_level_api_fields + result = Geocoder.search("134.201.250.155").first + assert_equal "134.201.250.155", result.ip + assert_equal "134.201.250.155", result.hostname + assert_equal "NA", result.continent_code + assert_equal "North America", result.continent_name + assert_equal "US", result.country_code + assert_equal "United States", result.country_name + assert_equal "CA", result.region_code + assert_equal "California", result.region_name + assert_equal "Los Angeles", result.city + assert_equal "90013", result.zip + assert_equal 34.0453, result.latitude + assert_equal (-118.2413), result.longitude + end + + def test_nested_api_fields + result = Geocoder.search("134.201.250.155").first + + assert result.location.is_a?(Hash) + assert_equal 5368361, result.location['geoname_id'] + + assert result.time_zone.is_a?(Hash) + assert_equal "America/Los_Angeles", result.time_zone['id'] + + assert result.currency.is_a?(Hash) + assert_equal "USD", result.currency['code'] + + assert result.connection.is_a?(Hash) + assert_equal 25876, result.connection['asn'] + + assert result.security.is_a?(Hash) + end + + def test_required_base_fields + result = Geocoder.search("134.201.250.155").first + assert_equal "California", result.state + assert_equal "CA", result.state_code + assert_equal "United States", result.country + assert_equal "90013", result.postal_code + assert_equal [34.0453, -118.2413], result.coordinates + end + + def test_logs_deprecation_of_metro_code_field + result = Geocoder.search("134.201.250.155").first + result.metro_code + + assert @logger.logged?("Ipstack does not implement `metro_code` in api results. Please discontinue use.") + end + + def test_localhost_loopback + result = Geocoder.search("127.0.0.1").first + assert_equal "127.0.0.1", result.ip + assert_equal "RD", result.country_code + assert_equal "Reserved", result.country_name + end + + def test_localhost_loopback_defaults + result = Geocoder.search("127.0.0.1").first + assert_equal "127.0.0.1", result.ip + assert_equal "", result.hostname + assert_equal "", result.continent_code + assert_equal "", result.continent_name + assert_equal "RD", result.country_code + assert_equal "Reserved", result.country_name + assert_equal "", result.region_code + assert_equal "", result.region_name + assert_equal "", result.city + assert_equal "", result.zip + assert_equal 0, result.latitude + assert_equal 0, result.longitude + assert_equal({}, result.location) + assert_equal({}, result.time_zone) + assert_equal({}, result.currency) + assert_equal({}, result.connection) + end + + def test_localhost_private + result = Geocoder.search("172.19.0.1").first + assert_equal "172.19.0.1", result.ip + assert_equal "RD", result.country_code + assert_equal "Reserved", result.country_name + end + + def test_api_request_adds_access_key + lookup = Geocoder::Lookup.get(:ipstack) + assert_match 'http://api.ipstack.com/74.200.247.59?access_key=123', lookup.query_url(Geocoder::Query.new("74.200.247.59")) + end + + def test_api_request_adds_security_when_specified + lookup = Geocoder::Lookup.get(:ipstack) + + query_url = lookup.query_url(Geocoder::Query.new("74.200.247.59", params: { security: '1' })) + + assert_match(/&security=1/, query_url) + end + + def test_api_request_adds_hostname_when_specified + lookup = Geocoder::Lookup.get(:ipstack) + + query_url = lookup.query_url(Geocoder::Query.new("74.200.247.59", params: { hostname: '1' })) + + assert_match(/&hostname=1/, query_url) + end + + def test_api_request_adds_language_when_specified + lookup = Geocoder::Lookup.get(:ipstack) + + query_url = lookup.query_url(Geocoder::Query.new("74.200.247.59", params: { language: 'es' })) + + assert_match(/&language=es/, query_url) + end + + def test_api_request_adds_fields_when_specified + lookup = Geocoder::Lookup.get(:ipstack) + + query_url = lookup.query_url(Geocoder::Query.new("74.200.247.59", params: { fields: 'foo,bar' })) + + assert_match(/&fields=foo%2Cbar/, query_url) + end + + def test_logs_warning_when_errors_are_set_not_to_raise + Geocoder::Configuration.instance.data.clear + Geocoder::Configuration.set_defaults + Geocoder.configure(api_key: '123', ip_lookup: :ipstack, logger: @logger) + + lookup = Geocoder::Lookup.get(:ipstack) + + lookup.send(:results, Geocoder::Query.new("not_found")) + + assert @logger.logged?("Ipstack Geocoding API error: The requested resource does not exist.") + end + + def test_uses_lookup_specific_configuration + Geocoder::Configuration.instance.data.clear + Geocoder::Configuration.set_defaults + Geocoder.configure(api_key: '123', ip_lookup: :ipstack, logger: @logger, ipstack: { api_key: '345'}) + + lookup = Geocoder::Lookup.get(:ipstack) + assert_match 'http://api.ipstack.com/74.200.247.59?access_key=345', lookup.query_url(Geocoder::Query.new("74.200.247.59")) + end + + def test_not_authorized lookup = Geocoder::Lookup.get(:ipstack) + + error = assert_raise Geocoder::InvalidRequest do + lookup.send(:results, Geocoder::Query.new("not_found")) + end + + assert_equal error.message, "The requested resource does not exist." + end + + def test_missing_access_key + lookup = Geocoder::Lookup.get(:ipstack) + + error = assert_raise Geocoder::InvalidApiKey do + lookup.send(:results, Geocoder::Query.new("missing_access_key")) + end + + assert_equal error.message, "No API Key was specified." + end + + def test_invalid_access_key + lookup = Geocoder::Lookup.get(:ipstack) + + error = assert_raise Geocoder::InvalidApiKey do + lookup.send(:results, Geocoder::Query.new("invalid_access_key")) + end + + assert_equal error.message, "No API Key was specified or an invalid API Key was specified." + end + + def test_inactive_user + lookup = Geocoder::Lookup.get(:ipstack) + + error = assert_raise Geocoder::Error do + lookup.send(:results, Geocoder::Query.new("inactive_user")) + end + + assert_equal error.message, "The current user account is not active. User will be prompted to get in touch with Customer Support." + end + + def test_invalid_api_function + lookup = Geocoder::Lookup.get(:ipstack) + + error = assert_raise Geocoder::InvalidRequest do + lookup.send(:results, Geocoder::Query.new("invalid_api_function")) + end + + assert_equal error.message, "The requested API endpoint does not exist." + end + + def test_usage_limit + lookup = Geocoder::Lookup.get(:ipstack) + + error = assert_raise Geocoder::OverQueryLimitError do + lookup.send(:results, Geocoder::Query.new("usage_limit")) + end + + assert_equal error.message, "The maximum allowed amount of monthly API requests has been reached." + end + + def test_access_restricted + lookup = Geocoder::Lookup.get(:ipstack) + + error = assert_raise Geocoder::RequestDenied do + lookup.send(:results, Geocoder::Query.new("access_restricted")) + end + + assert_equal error.message, "The current subscription plan does not support this API endpoint." + end + + def test_protocol_access_restricted + lookup = Geocoder::Lookup.get(:ipstack) + + error = assert_raise Geocoder::RequestDenied do + lookup.send(:results, Geocoder::Query.new("protocol_access_restricted")) + end + + assert_equal error.message, "The user's current subscription plan does not support HTTPS Encryption." + end + + def test_invalid_fields + lookup = Geocoder::Lookup.get(:ipstack) + + error = assert_raise Geocoder::InvalidRequest do + lookup.send(:results, Geocoder::Query.new("invalid_fields")) + end + + assert_equal error.message, "One or more invalid fields were specified using the fields parameter." + end + + def test_too_many_ips + lookup = Geocoder::Lookup.get(:ipstack) + + error = assert_raise Geocoder::InvalidRequest do + lookup.send(:results, Geocoder::Query.new("too_many_ips")) + end + + assert_equal error.message, "Too many IPs have been specified for the Bulk Lookup Endpoint. (max. 50)" + end + + def test_batch_not_supported + lookup = Geocoder::Lookup.get(:ipstack) + + error = assert_raise Geocoder::RequestDenied do + lookup.send(:results, Geocoder::Query.new("batch_not_supported")) + end + + assert_equal error.message, "The Bulk Lookup Endpoint is not supported on the current subscription plan" + end +end diff --git a/test/unit/lookups/location_iq_test.rb b/test/unit/lookups/location_iq_test.rb index d2a80b6c2..f3739ecd5 100644 --- a/test/unit/lookups/location_iq_test.rb +++ b/test/unit/lookups/location_iq_test.rb @@ -12,7 +12,7 @@ def setup 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 + assert_match(/key=abc123/, query.url) end def test_raises_exception_with_invalid_api_key diff --git a/test/unit/lookups/mapbox_test.rb b/test/unit/lookups/mapbox_test.rb index 5976442ef..7610081bb 100644 --- a/test/unit/lookups/mapbox_test.rb +++ b/test/unit/lookups/mapbox_test.rb @@ -44,4 +44,16 @@ def test_raises_exception_with_invalid_api_key Geocoder.search("invalid api key") end end + + def test_truncates_query_at_semicolon + result = Geocoder.search("Madison Square Garden, New York, NY;123 Another St").first + assert_equal [40.749688, -73.991566], result.coordinates + end + + def test_mapbox_result_without_context + assert_nothing_raised do + result = Geocoder.search("Shanghai, China")[0] + assert_equal nil, result.city + end + end end diff --git a/test/unit/lookups/mapzen_test.rb b/test/unit/lookups/mapzen_test.rb deleted file mode 100644 index 83ad909d1..000000000 --- a/test/unit/lookups/mapzen_test.rb +++ /dev/null @@ -1,17 +0,0 @@ -# encoding: utf-8 -require 'test_helper' - -class MapzenTest < GeocoderTestCase - def setup - Geocoder.configure(lookup: :mapzen, api_key: 'abc123') - end - - def test_configure_default_endpoint - query = Geocoder::Query.new('Madison Square Garden, New York, NY') - assert_true query.url.start_with?('http://search.mapzen.com/v1/search'), query.url - end - - def test_inherits_from_pelias - assert_true Geocoder::Lookup::Mapzen.new.is_a?(Geocoder::Lookup::Pelias) - end -end diff --git a/test/unit/lookups/maxmind_test.rb b/test/unit/lookups/maxmind_test.rb index 6fc6cb024..99672c9b1 100644 --- a/test/unit/lookups/maxmind_test.rb +++ b/test/unit/lookups/maxmind_test.rb @@ -59,4 +59,16 @@ def test_maxmind_works_when_loopback_address_on_country result = Geocoder.search("127.0.0.1").first assert_equal "", result.country_code end + + def test_maxmind_works_when_private_address_on_omni + Geocoder.configure(maxmind: {service: :omni}) + result = Geocoder.search("172.19.0.1").first + assert_equal "", result.country_code + end + + def test_maxmind_works_when_private_address_on_country + Geocoder.configure(maxmind: {service: :country}) + result = Geocoder.search("172.19.0.1").first + assert_equal "", result.country_code + end end diff --git a/test/unit/lookups/nationaal_georegister_nl_test.rb b/test/unit/lookups/nationaal_georegister_nl_test.rb new file mode 100644 index 000000000..d2ac6193a --- /dev/null +++ b/test/unit/lookups/nationaal_georegister_nl_test.rb @@ -0,0 +1,23 @@ +# encoding: utf-8 +require 'test_helper' + +class NationaalGeoregisterNlTest < GeocoderTestCase + + def setup + Geocoder.configure(lookup: :nationaal_georegister_nl) + end + + def test_result_components + result = Geocoder.search('Nieuwezijds Voorburgwal 147, Amsterdam').first + + assert_equal result.street, 'Nieuwezijds Voorburgwal' + assert_equal result.street_number, '147' + assert_equal result.city, 'Amsterdam' + assert_equal result.postal_code, '1012RJ' + assert_equal result.address, 'Nieuwezijds Voorburgwal 147, 1012RJ Amsterdam' + assert_equal result.province, 'Noord-Holland' + assert_equal result.province_code, 'PV27' + assert_equal result.country_code, 'NL' + end + +end diff --git a/test/unit/lookups/okf_test.rb b/test/unit/lookups/okf_test.rb deleted file mode 100644 index b05cce85d..000000000 --- a/test/unit/lookups/okf_test.rb +++ /dev/null @@ -1,37 +0,0 @@ -# encoding: utf-8 -require 'test_helper' - -class OkfTest < GeocoderTestCase - - def setup - Geocoder.configure(lookup: :okf) - end - - def test_okf_result_components - result = Geocoder.search("Kirstinmäki 11b28").first - assert_equal "Espoo", - result.address_components_of_type(:administrative_area_level_3).first['long_name'] - end - - def test_okf_result_components_contains_route - result = Geocoder.search("Kirstinmäki 11b28").first - assert_equal "Kirstinmäki", - result.address_components_of_type(:route).first['long_name'] - end - - def test_okf_result_components_contains_street_number - result = Geocoder.search("Kirstinmäki 11b28").first - assert_equal "1", - result.address_components_of_type(:street_number).first['long_name'] - end - - def test_okf_street_address_returns_formatted_street_address - result = Geocoder.search("Kirstinmäki 11b28").first - assert_equal "Kirstinmäki 1", result.street_address - end - - def test_okf_precision - result = Geocoder.search("Kirstinmäki 11b28").first - assert_equal "RANGE_INTERPOLATED", result.precision - end -end diff --git a/test/unit/lookups/osmnames_test.rb b/test/unit/lookups/osmnames_test.rb new file mode 100644 index 000000000..dbb2cee39 --- /dev/null +++ b/test/unit/lookups/osmnames_test.rb @@ -0,0 +1,63 @@ +# encoding: utf-8 +require 'test_helper' + +class OsmnamesTest < GeocoderTestCase + def setup + Geocoder.configure(lookup: :osmnames) + set_api_key!(:osmnames) + end + + def test_url_contains_api_key + Geocoder.configure(osmnames: {api_key: 'abc123'}) + query = Geocoder::Query.new('test') + assert_includes query.url, 'key=abc123' + end + + def test_url_contains_query_base + query = Geocoder::Query.new("Madison Square Garden, New York, NY") + assert_includes query.url, 'geocoder.tilehosting.com/q/Madison' + end + + def test_url_contains_country_code + query = Geocoder::Query.new("test", country_code: 'US') + assert_includes query.url, 'https://geocoder.tilehosting.com/us/q/' + end + + def test_result_components + result = Geocoder.search('Madison Square Garden, New York, NY').first + assert_equal [40.693073, -73.878418], result.coordinates + assert_equal 'New York City, New York, United States of America', result.address + assert_equal 'New York', result.state + assert_equal 'New York City', result.city + assert_equal 'us', result.country_code + end + + def test_result_for_reverse_geocode + result = Geocoder.search('-73.878418, 40.693073').first + assert_equal 'New York City, New York, United States of America', result.address + assert_equal 'New York', result.state + assert_equal 'New York City', result.city + assert_equal 'us', result.country_code + end + + def test_url_for_reverse_geocode + query = Geocoder::Query.new("-73.878418, 40.693073") + assert_includes query.url, 'https://geocoder.tilehosting.com/r/-73.878418/40.693073.js' + end + + def test_result_viewport + result = Geocoder.search("Madison Square Garden, New York, NY").first + assert_equal [40.477398, -74.259087, 40.91618, -73.70018], result.viewport + end + + def test_no_results + assert_equal [], Geocoder.search("no results") + end + + def test_raises_exception_when_return_message_error + Geocoder.configure(always_raise: [Geocoder::InvalidRequest]) + assert_raises Geocoder::InvalidRequest.new("Invalid attribute value.") do + Geocoder.search("invalid request") + end + end +end diff --git a/test/unit/lookups/ovi_test.rb b/test/unit/lookups/ovi_test.rb deleted file mode 100644 index 1404ed3ea..000000000 --- a/test/unit/lookups/ovi_test.rb +++ /dev/null @@ -1,17 +0,0 @@ -# encoding: utf-8 -$: << File.join(File.dirname(__FILE__), "..", "..") -require 'test_helper' - -class OviTest < GeocoderTestCase - - def setup - Geocoder.configure(lookup: :ovi) - end - - def test_ovi_viewport - result = Geocoder.search("Madison Square Garden, New York, NY").first - assert_equal [40.7493451, -73.9948616, 40.7515934, -73.9918938], - result.viewport - end - -end diff --git a/test/unit/lookups/pelias_test.rb b/test/unit/lookups/pelias_test.rb index 13566d2a3..47dfa1718 100644 --- a/test/unit/lookups/pelias_test.rb +++ b/test/unit/lookups/pelias_test.rb @@ -17,14 +17,9 @@ def test_configure_custom_endpoint assert_true query.url.start_with?('http://self.hosted.pelias/proxy/v1/search'), query.url end - def test_query_url_defaults_to_one - query = Geocoder::Query.new('Madison Square Garden, New York, NY') - assert_match 'size=1', query.url - end - def test_query_for_reverse_geocode lookup = Geocoder::Lookup::Pelias.new url = lookup.query_url(Geocoder::Query.new([45.423733, -75.676333])) - assert_match(/point.lat=45.423733&point.lon=-75.676333&size=1/, url) + assert_match(/point.lat=45.423733&point.lon=-75.676333/, url) end end diff --git a/test/unit/lookups/pickpoint_test.rb b/test/unit/lookups/pickpoint_test.rb index a4cb4cd7d..be3facac0 100644 --- a/test/unit/lookups/pickpoint_test.rb +++ b/test/unit/lookups/pickpoint_test.rb @@ -14,14 +14,13 @@ def test_result_components def test_result_viewport result = Geocoder.search("Madison Square Garden, New York, NY").first - assert_equal [40.749828338623, -73.9943389892578, 40.7511596679688, -73.9926528930664], - result.viewport + assert_equal [40.749828338623, -73.9943389892578, 40.7511596679688, -73.9926528930664], result.viewport end def test_url_contains_api_key Geocoder.configure(pickpoint: {api_key: "pickpoint-api-key"}) query = Geocoder::Query.new("Leadville, CO") - assert_equal "https://api.pickpoint.io/v1/forward?key=pickpoint-api-key&accept-language=en&addressdetails=1&format=json&q=Leadville%2C+CO", query.url + assert_match(/key=pickpoint-api-key/, query.url) end def test_raises_exception_with_invalid_api_key diff --git a/test/unit/lookups/pointpin_test.rb b/test/unit/lookups/pointpin_test.rb index 86549e994..3d81c6624 100644 --- a/test/unit/lookups/pointpin_test.rb +++ b/test/unit/lookups/pointpin_test.rb @@ -12,6 +12,16 @@ def test_result_on_ip_address_search assert result.is_a?(Geocoder::Result::Pointpin) end + def test_result_on_loopback_ip_address_search + results = Geocoder.search("127.0.0.1") + assert_equal 0, results.length + end + + def test_result_on_private_ip_address_search + results = Geocoder.search("172.19.0.1") + assert_equal 0, results.length + end + def test_result_components result = Geocoder.search("80.111.55.55").first assert_equal "Dublin, Dublin City, 8, Ireland", result.address @@ -19,7 +29,7 @@ def test_result_components def test_no_results silence_warnings do - results = Geocoder.search("10.10.10.10") + results = Geocoder.search("8.8.8.8") assert_equal 0, results.length end end diff --git a/test/unit/lookups/postcodes_io_test.rb b/test/unit/lookups/postcodes_io_test.rb new file mode 100644 index 000000000..30fd73785 --- /dev/null +++ b/test/unit/lookups/postcodes_io_test.rb @@ -0,0 +1,21 @@ +# encoding: utf-8 +require 'test_helper' + +class PostcodesIoTest < GeocoderTestCase + + def setup + Geocoder.configure(lookup: :postcodes_io) + end + + def test_result_on_postcode_search + results = Geocoder.search('WR26NJ') + + assert_equal 1, results.size + assert_equal 'Worcestershire', results.first.county + assert_equal [52.2327158260535, -2.26972239639173], results.first.coordinates + end + + def test_no_results + assert_equal [], Geocoder.search('no results') + end +end diff --git a/test/unit/lookups/smarty_streets_test.rb b/test/unit/lookups/smarty_streets_test.rb index fe89335e8..d25048488 100644 --- a/test/unit/lookups/smarty_streets_test.rb +++ b/test/unit/lookups/smarty_streets_test.rb @@ -29,6 +29,11 @@ def test_query_for_zipfour_geocode assert_match(/us-zipcode\.api\.smartystreets\.com\/lookup\?/, query.url) end + def test_query_for_international_geocode + query = Geocoder::Query.new("13 rue yves toudic 75010", country: "France") + assert_match(/international-street\.api\.smartystreets\.com\/verify\?/, query.url) + end + def test_smarty_streets_result_components result = Geocoder.search("Madison Square Garden, New York, NY").first assert_equal "Penn", result.street @@ -36,6 +41,7 @@ def test_smarty_streets_result_components assert_equal "1703", result.zip4 assert_equal "New York", result.city assert_equal "36061", result.fips + assert_equal "US", result.country_code assert !result.zipcode_endpoint? end @@ -44,9 +50,19 @@ def test_smarty_streets_result_components_with_zipcode_only_query assert_equal "Brooklyn", result.city assert_equal "New York", result.state assert_equal "NY", result.state_code + assert_equal "US", result.country_code assert result.zipcode_endpoint? end + def test_smarty_streets_result_components_with_international_query + result = Geocoder.search("13 rue yves toudic 75010", country: "France").first + assert_equal 'Yves Toudic', result.street + assert_equal 'Paris', result.city + assert_equal '75010', result.postal_code + assert_equal 'FRA', result.country_code + assert result.international_endpoint? + end + def test_smarty_streets_when_longitude_latitude_does_not_exist result = Geocoder.search("96628").first assert_equal nil, result.coordinates @@ -57,6 +73,12 @@ def test_no_results assert_equal 0, results.length end + def test_invalid_zipcode_returns_no_results + assert_nothing_raised do + assert_nil Geocoder.search("10300").first + end + end + def test_raises_exception_on_error_http_status error_statuses = { '400' => Geocoder::InvalidRequest, diff --git a/test/unit/lookups/telize_test.rb b/test/unit/lookups/telize_test.rb index aa6e4dbe5..744a9069b 100644 --- a/test/unit/lookups/telize_test.rb +++ b/test/unit/lookups/telize_test.rb @@ -4,7 +4,41 @@ class TelizeTest < GeocoderTestCase def setup - Geocoder.configure(ip_lookup: :telize) + Geocoder.configure(ip_lookup: :telize, telize: {host: nil}) + end + + def test_query_url + lookup = Geocoder::Lookup::Telize.new + query = Geocoder::Query.new("74.200.247.59") + assert_match %r{^https://telize-v1\.p\.rapidapi\.com/location/74\.200\.247\.59}, lookup.query_url(query) + end + + def test_includes_api_key_when_set + Geocoder.configure(api_key: "api_key") + lookup = Geocoder::Lookup::Telize.new + query = Geocoder::Query.new("74.200.247.59") + assert_match %r{/location/74\.200\.247\.59\?rapidapi-key=api_key}, lookup.query_url(query) + end + + def test_uses_custom_host_when_set + Geocoder.configure(telize: {host: "example.com"}) + lookup = Geocoder::Lookup::Telize.new + query = Geocoder::Query.new("74.200.247.59") + assert_match %r{^http://example\.com/location/74\.200\.247\.59$}, lookup.query_url(query) + end + + def test_allows_https_when_custom_host + Geocoder.configure(use_https: true, telize: {host: "example.com"}) + lookup = Geocoder::Lookup::Telize.new + query = Geocoder::Query.new("74.200.247.59") + assert_match %r{^https://example\.com}, lookup.query_url(query) + end + + def test_requires_https_when_not_custom_host + Geocoder.configure(use_https: false) + lookup = Geocoder::Lookup::Telize.new + query = Geocoder::Query.new("74.200.247.59") + assert_match %r{^https://telize-v1\.p\.rapidapi\.com}, lookup.query_url(query) end def test_result_on_ip_address_search @@ -12,13 +46,29 @@ def test_result_on_ip_address_search assert result.is_a?(Geocoder::Result::Telize) end + def test_result_on_loopback_ip_address_search + result = Geocoder.search("127.0.0.1").first + assert_equal "127.0.0.1", result.ip + assert_equal '', result.country_code + assert_equal '', result.country + end + + def test_result_on_private_ip_address_search + result = Geocoder.search("172.19.0.1").first + assert_equal "172.19.0.1", result.ip + assert_equal '', result.country_code + assert_equal '', result.country + end + def test_result_components result = Geocoder.search("74.200.247.59").first - assert_equal "Plano, TX 75093, United States", result.address + assert_equal "Jersey City, NJ 07302, United States", result.address + assert_equal "US", result.country_code + assert_equal [40.7209, -74.0468], result.coordinates end def test_no_results - results = Geocoder.search("10.10.10.10") + results = Geocoder.search("8.8.8.8") assert_equal 0, results.length end @@ -26,4 +76,14 @@ def test_invalid_address results = Geocoder.search("555.555.555.555", ip_address: true) assert_equal 0, results.length end + + def test_cache_key_strips_off_query_string + Geocoder.configure(telize: {api_key: "xxxxx"}) + lookup = Geocoder::Lookup.get(:telize) + query = Geocoder::Query.new("8.8.8.8") + qurl = lookup.send(:query_url, query) + key = lookup.send(:cache_key, query) + assert qurl.include?("rapidapi-key") + assert !key.include?("rapidapi-key") + end end diff --git a/test/unit/lookups/uk_ordnance_survey_names.rb b/test/unit/lookups/uk_ordnance_survey_names.rb new file mode 100644 index 000000000..629d8ac4c --- /dev/null +++ b/test/unit/lookups/uk_ordnance_survey_names.rb @@ -0,0 +1,22 @@ +# encoding: utf-8 +require 'test_helper' + +class UkOrdnanceSurveyNamesTest < GeocoderTestCase + + def setup + Geocoder.configure(lookup: :uk_ordnance_survey_names) + set_api_key!(:uk_ordnance_survey_names) + end + + def test_result_on_placename_search + result = Geocoder.search('London').first + assert_in_delta 51.51437, result.coordinates[0] + assert_in_delta -0.09227, result.coordinates[1] + end + + def test_result_on_postcode_search + result = Geocoder.search('SW1A1AA').first + assert_in_delta 51.50100, result.coordinates[0] + assert_in_delta -0.14157, result.coordinates[1] + end +end diff --git a/test/unit/lookups/yandex_test.rb b/test/unit/lookups/yandex_test.rb index 45c4c26cb..9887dfd8b 100644 --- a/test/unit/lookups/yandex_test.rb +++ b/test/unit/lookups/yandex_test.rb @@ -3,14 +3,13 @@ require 'test_helper' class YandexTest < GeocoderTestCase - def setup - Geocoder.configure(lookup: :yandex) + Geocoder.configure(lookup: :yandex, language: :en) end def test_yandex_viewport - result = Geocoder.search('Кремль, Moscow, Russia').first - assert_equal [55.733361, 37.584182, 55.770517, 37.650064], + result = Geocoder.search('Kremlin, Moscow, Russia').first + assert_equal [55.748189, 37.612587, 55.755044, 37.623187], result.viewport end @@ -26,6 +25,150 @@ def test_yandex_query_url_contains_bbox "Some Intersection", :bounds => [[40.0, -120.0], [39.0, -121.0]] )) - assert_match(/bbox=40.0+%2C-120.0+%7E39.0+%2C-121.0+/, url) + if RUBY_VERSION < '2.5.0' + assert_match(/bbox=40.0+%2C-120.0+%7E39.0+%2C-121.0+/, url) + else + assert_match(/bbox=40.0+%2C-120.0+~39.0+%2C-121.0+/, url) + end + end + + def test_yandex_result_without_city_does_not_raise_exception + assert_nothing_raised do + set_api_key!(:yandex) + result = Geocoder.search("no city and town").first + assert_equal "", result.city + end + end + + def test_yandex_result_without_admin_area_no_exception + assert_nothing_raised do + set_api_key!(:yandex) + result = Geocoder.search("no administrative area").first + assert_equal "", result.city + end + end + + def test_yandex_result_new_york + assert_nothing_raised do + set_api_key!(:yandex) + result = Geocoder.search("new york").first + assert_equal "", result.city + end + end + + def test_yandex_result_kind + assert_nothing_raised do + set_api_key!(:yandex) + ["new york", [45.423733, -75.676333], "no city and town"].each do |query| + Geocoder.search("new york").first.kind + end + end + end + + def test_yandex_result_without_locality_name + assert_nothing_raised do + set_api_key!(:yandex) + result = Geocoder.search("canada rue dupuis 14")[6] + assert_equal "", result.city + end + end + + def test_yandex_result_returns_street_name + assert_nothing_raised do + set_api_key!(:yandex) + result = Geocoder.search("canada rue dupuis 14")[6] + assert_equal "Rue Hormidas-Dupuis", result.street + end + end + + def test_yandex_result_returns_street_number + assert_nothing_raised do + set_api_key!(:yandex) + result = Geocoder.search("canada rue dupuis 14")[6] + assert_equal "14", result.street_number + end + end + + def test_yandex_find_in_hash_method + result = Geocoder::Result::Yandex.new({}) + hash = { + 'root_node' => { + 'node_1' => [1, 2, 3], + 'node_2' => { + 'data' => 'foo' + } + } + } + + assert_equal [1, 2, 3], result.send(:find_in_hash, hash, 'root_node', 'node_1') + assert_equal "foo", result.send(:find_in_hash, hash, 'root_node', 'node_2', 'data') + assert_equal nil, result.send(:find_in_hash, hash, 'root_node', 'node_3') + assert_equal nil, result.send(:find_in_hash, hash, 'root_node', 'node_2', 'another_data') + assert_equal nil, result.send(:find_in_hash, hash, 'root_node', 'node_2', 'data', 'x') + end + + def test_yandex_maximum_precision_on_russian_address + result = Geocoder.search('putilkovo novotushinskaya 5').first + + assert_equal [55.872258, 37.403522], result.coordinates + assert_equal [55.86995, 37.399416, 55.874567, 37.407627], result.viewport + + assert_equal "Russia, Moscow Region, gorodskoy okrug Krasnogorsk, " \ + "derevnya Putilkovo, Novotushinskaya ulitsa, 5", + result.address + assert_equal "derevnya Putilkovo", result.city + assert_equal "Russia", result.country + assert_equal "RU", result.country_code + assert_equal "Moscow Region", result.state + assert_equal "gorodskoy okrug Krasnogorsk", result.sub_state + assert_equal "", result.state_code + assert_equal "Novotushinskaya ulitsa", result.street + assert_equal "5", result.street_number + assert_equal "", result.premise_name + assert_equal "143441", result.postal_code + assert_equal "house", result.kind + assert_equal "exact", result.precision + end + + def test_yandex_hydro_object + result = Geocoder.search('volga river').first + + assert_equal [49.550996, 45.139984], result.coordinates + assert_equal [45.697053, 32.468241, 58.194645, 50.181608], result.viewport + + assert_equal "Russia, Volga River", result.address + assert_equal "", result.city + assert_equal "Russia", result.country + assert_equal "RU", result.country_code + assert_equal "", result.state + assert_equal "", result.sub_state + assert_equal "", result.state_code + assert_equal "", result.street + assert_equal "", result.street_number + assert_equal "Volga River", result.premise_name + assert_equal "", result.postal_code + assert_equal "hydro", result.kind + assert_equal "other", result.precision + end + + def test_yandex_province_object + result = Geocoder.search('ontario').first + + assert_equal [49.294248, -87.170557], result.coordinates + assert_equal [41.704494, -95.153382, 56.88699, -74.321387], result.viewport + + assert_equal "Canada, Ontario", result.address + assert_equal "", result.city + assert_equal "Canada", result.country + assert_equal "CA", result.country_code + assert_equal "Ontario", result.state + assert_equal "", result.sub_state + assert_equal "", result.state_code + assert_equal "", result.street + assert_equal "", result.street_number + assert_equal "", result.premise_name + assert_equal "", result.postal_code + assert_equal "province", result.kind + assert_equal "other", result.precision end end diff --git a/test/unit/method_aliases_test.rb b/test/unit/method_aliases_test.rb index d33afc483..c0a0ba7be 100644 --- a/test/unit/method_aliases_test.rb +++ b/test/unit/method_aliases_test.rb @@ -11,15 +11,11 @@ def test_distance_from_is_alias_for_distance_to def test_fetch_coordinates_is_alias_for_geocode v = Place.new(*geocoded_object_params(:msg)) - coords = [40.750354, -73.993371] - assert_equal coords, v.fetch_coordinates - assert_equal coords, [v.latitude, v.longitude] + assert_equal [Float, Float], v.fetch_coordinates.map(&:class) end def test_fetch_address_is_alias_for_reverse_geocode v = PlaceReverseGeocoded.new(*reverse_geocoded_object_params(:msg)) - address = "4 Penn Plaza, New York, NY 10001, USA" - assert_equal address, v.fetch_address - assert_equal address, v.address + assert_match(/New York/, v.fetch_address) end end diff --git a/test/unit/model_test.rb b/test/unit/model_test.rb index b2fe06960..39612fd73 100644 --- a/test/unit/model_test.rb +++ b/test/unit/model_test.rb @@ -5,9 +5,8 @@ class ModelTest < GeocoderTestCase def test_geocode_with_block_runs_block e = PlaceWithCustomResultsHandling.new(*geocoded_object_params(:msg)) - coords = [40.750354, -73.993371] e.geocode - assert_equal coords.map{ |c| c.to_s }.join(','), e.coords_string + assert_match(/[0-9\.,\-]+/, e.coords_string) end def test_geocode_with_block_doesnt_auto_assign_coordinates @@ -20,7 +19,7 @@ def test_geocode_with_block_doesnt_auto_assign_coordinates def test_reverse_geocode_with_block_runs_block e = PlaceReverseGeocodedWithCustomResultsHandling.new(*reverse_geocoded_object_params(:msg)) e.reverse_geocode - assert_equal "US", e.country + assert_equal "US", e.country.upcase end def test_reverse_geocode_with_block_doesnt_auto_assign_address diff --git a/test/unit/mongoid_test.rb b/test/unit/mongoid_test.rb index cea0fa73d..8a9ca1aca 100644 --- a/test/unit/mongoid_test.rb +++ b/test/unit/mongoid_test.rb @@ -44,18 +44,18 @@ def test_geocoded_with_custom_handling p = PlaceUsingMongoidWithCustomResultsHandling.new(*geocoded_object_params(:msg)) p.location = [40.750354, -73.993371] p.geocode - assert p.coords_string == "40.750354,-73.993371" + assert_match(/[0-9\.,\-]+/, p.coords_string) end def test_reverse_geocoded p = PlaceUsingMongoidReverseGeocoded.new(*reverse_geocoded_object_params(:msg)) p.reverse_geocode - assert p.address == "4 Penn Plaza, New York, NY 10001, USA" + assert_match(/New York/, p.address) end def test_reverse_geocoded_with_custom_handling p = PlaceUsingMongoidReverseGeocodedWithCustomResultsHandling.new(*reverse_geocoded_object_params(:msg)) p.reverse_geocode - assert p.country == "US" + assert_equal "US", p.country.upcase end end diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index 51c713c36..5675461b4 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -3,9 +3,15 @@ class QueryTest < GeocoderTestCase - def test_ip_address_detection + def test_detect_ipv4 assert Geocoder::Query.new("232.65.123.94").ip_address? + end + + def test_detect_ipv6 assert Geocoder::Query.new("3ffe:0b00:0000:0000:0001:0000:0000:000a").ip_address? + end + + def test_detect_non_ip_address assert !Geocoder::Query.new("232.65.123.94.43").ip_address? assert !Geocoder::Query.new("::ffff:123.456.789").ip_address? end @@ -34,11 +40,27 @@ def test_coordinates_detection assert !Geocoder::Query.new("Test\n51.178844, -1.826189").coordinates? end + def test_internal_ip_address + assert Geocoder::Query.new("127.0.0.1").internal_ip_address? + assert Geocoder::Query.new("172.19.0.1").internal_ip_address? + assert Geocoder::Query.new("10.100.100.1").internal_ip_address? + assert Geocoder::Query.new("192.168.0.1").internal_ip_address? + assert !Geocoder::Query.new("232.65.123.234").internal_ip_address? + end + def test_loopback_ip_address assert Geocoder::Query.new("127.0.0.1").loopback_ip_address? assert !Geocoder::Query.new("232.65.123.234").loopback_ip_address? end + def test_private_ip_address + assert Geocoder::Query.new("172.19.0.1").private_ip_address? + assert Geocoder::Query.new("10.100.100.1").private_ip_address? + assert Geocoder::Query.new("192.168.0.1").private_ip_address? + assert !Geocoder::Query.new("127.0.0.1").private_ip_address? + assert !Geocoder::Query.new("232.65.123.234").private_ip_address? + end + def test_sanitized_text_with_array q = Geocoder::Query.new([43.1313,11.3131]) assert_equal "43.1313,11.3131", q.sanitized_text diff --git a/test/unit/rake_task_test.rb b/test/unit/rake_task_test.rb deleted file mode 100644 index 0818b3f3b..000000000 --- a/test/unit/rake_task_test.rb +++ /dev/null @@ -1,20 +0,0 @@ -# encoding: utf-8 -require 'test_helper' - -class RakeTaskTest < GeocoderTestCase - def setup - Rake.application.rake_require "tasks/geocoder" - Rake::Task.define_task(:environment) - end - - def test_rake_task_geocode_raise_specify_class_message - assert_raise(RuntimeError, "Please specify a CLASS (model)") do - Rake.application.invoke_task("geocode:all") - end - end - - def test_rake_task_geocode_specify_class - ENV['CLASS'] = 'Place' - assert_nil Rake.application.invoke_task("geocode:all") - end -end diff --git a/test/unit/request_test.rb b/test/unit/request_test.rb index 127f5f4f3..a77f5bf26 100644 --- a/test/unit/request_test.rb +++ b/test/unit/request_test.rb @@ -10,6 +10,11 @@ def initialize(headers={}, ip="") super(super_env) end end + + def setup + Geocoder.configure(ip_lookup: :freegeoip) + end + def test_http_x_real_ip req = MockRequest.new({"HTTP_X_REAL_IP" => "74.200.247.59"}) assert req.location.is_a?(Geocoder::Result::Freegeoip) @@ -48,6 +53,10 @@ def test_with_loopback_x_forwarded_for req = MockRequest.new({"HTTP_X_FORWARDED_FOR" => "127.0.0.1"}, "74.200.247.59") assert_equal "US", req.location.country_code end + def test_with_private_x_forwarded_for + req = MockRequest.new({"HTTP_X_FORWARDED_FOR" => "172.19.0.1"}, "74.200.247.59") + assert_equal "US", req.location.country_code + end def test_http_x_forwarded_for_with_misconfigured_proxies req = MockRequest.new({"HTTP_X_FORWARDED_FOR" => ","}, "74.200.247.59") assert req.location.is_a?(Geocoder::Result::Freegeoip) @@ -72,6 +81,12 @@ def test_geocoder_remove_port_from_addresses_with_port req = MockRequest.new() assert_equal expected_ips, req.send(:geocoder_remove_port_from_addresses, ips) end + def test_geocoder_remove_port_from_ipv6_addresses_with_port + expected_ips = ['2600:1008:b16e:26da:ecb3:22f7:6be4:2137', '2600:1901:0:2df5::', '2001:db8:1f70::999:de8:7648:6e8', '10.128.0.2'] + ips = ['2600:1008:b16e:26da:ecb3:22f7:6be4:2137', '2600:1901:0:2df5::', '[2001:db8:1f70::999:de8:7648:6e8]:100', '10.128.0.2'] + req = MockRequest.new() + assert_equal expected_ips, req.send(:geocoder_remove_port_from_addresses, ips) + end def test_geocoder_remove_port_from_addresses_without_port expected_ips = ['127.0.0.1', '127.0.0.2', '127.0.0.3'] ips = ['127.0.0.1', '127.0.0.2', '127.0.0.3'] @@ -90,4 +105,4 @@ def test_geocoder_reject_non_ipv4_addresses_with_bad_ips req = MockRequest.new() assert_equal expected_ips, req.send(:geocoder_reject_non_ipv4_addresses, ips) end -end \ No newline at end of file +end diff --git a/test/unit/result_test.rb b/test/unit/result_test.rb index ecb31377d..410c31fdc 100644 --- a/test/unit/result_test.rb +++ b/test/unit/result_test.rb @@ -3,91 +3,24 @@ class ResultTest < GeocoderTestCase - def test_result_has_required_attributes + def test_forward_geocoding_result_has_required_attributes Geocoder::Lookup.all_services_except_test.each do |l| + next if l == :ip2location # has pay-per-attribute pricing model Geocoder.configure(:lookup => l) set_api_key!(l) - result = Geocoder.search([45.423733, -75.676333]).first + result = Geocoder.search("Madison Square Garden").first assert_result_has_required_attributes(result) end end - def test_result_has_coords_in_reasonable_range_for_madison_square_garden - Geocoder::Lookup.street_services.each do |l| - next unless File.exist?(File.join("test", "fixtures", "#{l.to_s}_madison_square_garden")) - Geocoder.configure(:lookup => l) - set_api_key!(l) - result = Geocoder.search("Madison Square Garden, New York, NY 10001, United States").first - assert (result.latitude > 40 and result.latitude < 41), "Lookup #{l} latitude out of range" - assert (result.longitude > -74 and result.longitude < -73), "Lookup #{l} longitude out of range" - end - end - - def test_result_accepts_reverse_coords_in_reasonable_range_for_madison_square_garden - Geocoder::Lookup.street_services.each do |l| - next unless File.exist?(File.join("test", "fixtures", "#{l.to_s}_madison_square_garden")) - next if [:bing, :esri, :geocoder_ca, :google_places_search, :geocoder_us, :geoportail_lu].include? l # Reverse fixture does not match forward + def test_reverse_geocoding_result_has_required_attributes + Geocoder::Lookup.all_services_except_test.each do |l| + next if l == :ip2location # has pay-per-attribute pricing model + next if l == :nationaal_georegister_nl # no reverse geocoding Geocoder.configure(:lookup => l) set_api_key!(l) - result = Geocoder.search([40.750354, -73.993371]).first - assert (["New York", "New York City"].include? result.city), "Reverse lookup #{l} City does not match" - assert (result.latitude > 40 and result.latitude < 41), "Reverse lookup #{l} latitude out of range" - assert (result.longitude > -74 and result.longitude < -73), "Reverse lookup #{l} longitude out of range" - end - end - - def test_yandex_result_without_city_does_not_raise_exception - assert_nothing_raised do - Geocoder.configure(:lookup => :yandex) - set_api_key!(:yandex) - result = Geocoder.search("no city and town").first - assert_equal "", result.city - end - end - - def test_yandex_result_without_admin_area_no_exception - assert_nothing_raised do - Geocoder.configure(:lookup => :yandex) - set_api_key!(:yandex) - result = Geocoder.search("no administrative area").first - assert_equal "", result.city - end - end - - def test_yandex_result_new_york - assert_nothing_raised do - Geocoder.configure(:lookup => :yandex) - set_api_key!(:yandex) - result = Geocoder.search("new york").first - assert_equal "", result.city - end - end - - def test_yandex_result_kind - assert_nothing_raised do - Geocoder.configure(:lookup => :yandex) - set_api_key!(:yandex) - ["new york", [45.423733, -75.676333], "no city and town"].each do |query| - Geocoder.search("new york").first.kind - end - end - end - - def test_yandex_result_without_locality_name - assert_nothing_raised do - Geocoder.configure(:lookup => :yandex) - set_api_key!(:yandex) - result = Geocoder.search("canada rue dupuis 14")[6] - assert_equal "", result.city - end - end - - def test_mapbox_result_without_context - assert_nothing_raised do - Geocoder.configure(:lookup => :mapbox) - set_api_key!(:mapbox) - result = Geocoder.search("Shanghai, China")[0] - assert_equal nil, result.city + result = Geocoder.search([45.423733, -75.676333]).first + assert_result_has_required_attributes(result) end end