Skip to content

Commit

Permalink
Use current map center as proximity hint
Browse files Browse the repository at this point in the history
When geocoding pass the current map center as 'proximity', which is a
new-ish feature of the OpenCage API that adjusts the order of results
that come back from the geocoder.

For example if the map is centered on London, UK then a search for
Croydon comes back with CR0 1SZ, but if the map is centered on Sydney,
Australia then a search for Croydon comes back with Croydon NSW 2132.
  • Loading branch information
kaoru committed Sep 30, 2018
1 parent e81e2ce commit 9e957bd
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
13 changes: 12 additions & 1 deletion dist/css/L.Control.OpenCageData.Search.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/css/L.Control.OpenCageSearch.dev.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* OpenCage Data Search Control v1.1.4 - 2018-08-28
* OpenCage Data Search Control v1.1.5 - 2018-09-30
* Copyright (c) 2018, OpenCage Data
* info@opencagedata.com
* https://opencagedata.com
Expand Down
9 changes: 7 additions & 2 deletions dist/js/L.Control.OpenCageSearch.dev.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* OpenCage Data Search Control v1.1.4 - 2018-08-28
* OpenCage Data Search Control v1.1.5 - 2018-09-30
* Copyright (c) 2018, OpenCage Data
* info@opencagedata.com
* https://opencagedata.com
Expand Down Expand Up @@ -281,11 +281,16 @@
},

geocode: function(query, cb, context) {
var proximity = {};
if (context && context._map && context._map.getCenter()) {
var center = context._map.getCenter();
proximity.proximity = center.lat + "," + center.lng;
}
L.Control.OpenCageSearch.jsonp(this.options.serviceUrl + 'json/', L.extend({
q: query,
limit: this.options.limit,
key: this.options.key
}, this.options.geocodingQueryParams),
}, proximity, this.options.geocodingQueryParams),
function(data) {
var results = [];
for (var i=data.results.length - 1; i >= 0; i--) {
Expand Down
5 changes: 2 additions & 3 deletions dist/js/L.Control.OpenCageSearch.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/js/L.Control.OpenCageSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,16 @@
},

geocode: function(query, cb, context) {
var proximity = {};
if (context && context._map && context._map.getCenter()) {
var center = context._map.getCenter();
proximity.proximity = center.lat + "," + center.lng;
}
L.Control.OpenCageSearch.jsonp(this.options.serviceUrl + 'json/', L.extend({
q: query,
limit: this.options.limit,
key: this.options.key
}, this.options.geocodingQueryParams),
}, proximity, this.options.geocodingQueryParams),
function(data) {
var results = [];
for (var i=data.results.length - 1; i >= 0; i--) {
Expand Down

0 comments on commit 9e957bd

Please sign in to comment.