Supplement Mapbox geocoder results with external geocoder API The Next CEO of Stack OverflowSeeking geocoding with advanced language support?Purely client-side geocoding options for a webmapLoad external tileJSON file in MapboxHow to Have Geocoding Service Return Results from Partial Street Name Input?Best approach for indexing a SQLite database containing geoJSON spatial objects?Mapbox GL JS Geocoder markerMapbox Error: Style is not done loadingMapBox geocoder results are not exact, how to enhance mapbox geocoding API?Geocoding to only reference Tileset using Mapbox GL JS?Looped query rendered feature function for a set of intersect points upon a GeoJSON building layer in Mapbox GL JS
Return the Closest Prime Number
How did the Bene Gesserit know how to make a Kwisatz Haderach?
Unreliable Magic - Is it worth it?
How do I make a variable always equal to the result of some calculations?
Complex fractions
How do I transpose the first and deepest levels of an arbitrarily nested array?
Is there a difference between "Fahrstuhl" and "Aufzug"
Is 'diverse range' a pleonastic phrase?
Would this house-rule that treats advantage as a +1 to the roll instead (and disadvantage as -1) and allows them to stack be balanced?
What happened in Rome, when the western empire "fell"?
If Nick Fury and Coulson already knew about aliens (Kree and Skrull) why did they wait until Thor's appearance to start making weapons?
Sending manuscript to multiple publishers
What is the result of assigning to std::vector<T>::begin()?
Are there any limitations on attacking while grappling?
What does convergence in distribution "in the Gromov–Hausdorff" sense mean?
How to prevent changing the value of variable?
Indicator light circuit
Why do variable in an inner function return nan when there is the same variable name at the inner function declared after log
What benefits would be gained by using human laborers instead of drones in deep sea mining?
Anatomically Correct Strange Women In Ponds Distributing Swords
Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?
Plot of histogram similar to output from @risk
Is it professional to write unrelated content in an almost-empty email?
Do I need to enable Dev Hub in my PROD Org?
Supplement Mapbox geocoder results with external geocoder API
The Next CEO of Stack OverflowSeeking geocoding with advanced language support?Purely client-side geocoding options for a webmapLoad external tileJSON file in MapboxHow to Have Geocoding Service Return Results from Partial Street Name Input?Best approach for indexing a SQLite database containing geoJSON spatial objects?Mapbox GL JS Geocoder markerMapbox Error: Style is not done loadingMapBox geocoder results are not exact, how to enhance mapbox geocoding API?Geocoding to only reference Tileset using Mapbox GL JS?Looped query rendered feature function for a set of intersect points upon a GeoJSON building layer in Mapbox GL JS
I am still learning JS so please bear with me.
I have built a Mapbox GL JS map and would like to supplement Mapbox geocoding results with those from an external geocoding API as many POIs I need are not returned with the standard Mapbox geocoder (such as campsites and national parks).
I have followed the tutorial to supplement results by querying local data here: Supplement forward geocoding search results from another data source
I have got this to work with local a geojson source however I cant get it to work when querying an external geocoder. I am testing with OpenCage.
My code for the geocoder instance on the map is:
// Load geojson source data
var myjson;
$.getJSON("<github hosted file>", function(json)
myjson = json;
);
// Local geocoder function
function forwardGeocoder(query)
var matchingFeatures = [];
for (var i = 0; i < myjson.features.length; i++)
var feature = myjson.features[i];
if (feature.properties.road_name.toLowerCase().search(query.toLowerCase()) !== -1)
feature['place_name'] = '🚙 ' + feature.properties.road_name;
feature['center'] = feature.geometry.coordinates;
matchingFeatures.push(feature);
return matchingFeatures;
//Add geocoder/search box
var geocoder = new MapboxGeocoder(
accessToken: mapboxgl.accessToken,
localGeocoder: forwardGeocoder,
country: 'au'
);
This works fine for local data pulled in from a geojson source (i.e. already loaded in the client side). When I try to add an external geocoder into the forwardGeocoder()
function, the query returns the correct geocoded results and I can get them to appear in the console but they dont appear in the standard mapbox geocoder results list. Code for the external geocoder (using OpenCage to test).
function forwardGeocoder(query)
var matchingFeatures = [];
$.ajax(
url: 'https://api.opencagedata.com/geocode/v1/geojson',
method: 'GET',
data:
'key': 'ab6ad6e3ad3043e2aeb897322ab038f0',
'q': query,
'pretty': 1
,
dataType: 'json',
statusCode:
200: function(response) // success
var listings = response.features;
//console.log(listings);
for (var i = 0; i < listings.length; i++)
var feature = listings[i];
if (feature.properties.formatted.toLowerCase().search(query.toLowerCase()) !== -1)
feature['place_name'] = '🚙 ' + feature.properties.formatted;
feature['center'] = feature.geometry.coordinates;
matchingFeatures.push(feature);
console.log(matchingFeatures);
return matchingFeatures;
,
402: function()
console.log('hit free-trial daily limit');
console.log('become a customer: https://opencagedata.com/pricing');
);
Console output from this function:
0:
center: (2) [145.516244, -37.4666249]
geometry: coordinates: Array(2), type: "Point"
place_name: "🚙 Aeroplane Track, Toolangi VIC, Australia"
properties:
annotations: DMS: …, MGRS: "55HCU6878852327", Maidenhead: "QF22sm18wa", Mercator: …, OSM: …, …
bounds: northeast: …, southwest: …
components: ISO_3166-1_alpha-2: "AU", ISO_3166-1_alpha-3: "AUS", _type: "road", continent: "Oceania", country: "Australia", …
confidence: 7
formatted: "Aeroplane Track, Toolangi VIC, Australia"
__proto__: Object
type: "Feature"
__proto__: Object
length: 1
__proto__: Array(0)
I am able to get results of the geocode to appear correctly (in the same format as the local data version) in the console (console.log(matchingFeatures)
) but the subsequent return matchingFeatures
doesnt seem to work to add them to the mapbox geocoder results.
Been searching around for days with no luck. Annoyingly I feel like this is a common problem as the Mapbox geocoder results are lacking in many ways.
geocoding mapbox point-of-interest
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I am still learning JS so please bear with me.
I have built a Mapbox GL JS map and would like to supplement Mapbox geocoding results with those from an external geocoding API as many POIs I need are not returned with the standard Mapbox geocoder (such as campsites and national parks).
I have followed the tutorial to supplement results by querying local data here: Supplement forward geocoding search results from another data source
I have got this to work with local a geojson source however I cant get it to work when querying an external geocoder. I am testing with OpenCage.
My code for the geocoder instance on the map is:
// Load geojson source data
var myjson;
$.getJSON("<github hosted file>", function(json)
myjson = json;
);
// Local geocoder function
function forwardGeocoder(query)
var matchingFeatures = [];
for (var i = 0; i < myjson.features.length; i++)
var feature = myjson.features[i];
if (feature.properties.road_name.toLowerCase().search(query.toLowerCase()) !== -1)
feature['place_name'] = '🚙 ' + feature.properties.road_name;
feature['center'] = feature.geometry.coordinates;
matchingFeatures.push(feature);
return matchingFeatures;
//Add geocoder/search box
var geocoder = new MapboxGeocoder(
accessToken: mapboxgl.accessToken,
localGeocoder: forwardGeocoder,
country: 'au'
);
This works fine for local data pulled in from a geojson source (i.e. already loaded in the client side). When I try to add an external geocoder into the forwardGeocoder()
function, the query returns the correct geocoded results and I can get them to appear in the console but they dont appear in the standard mapbox geocoder results list. Code for the external geocoder (using OpenCage to test).
function forwardGeocoder(query)
var matchingFeatures = [];
$.ajax(
url: 'https://api.opencagedata.com/geocode/v1/geojson',
method: 'GET',
data:
'key': 'ab6ad6e3ad3043e2aeb897322ab038f0',
'q': query,
'pretty': 1
,
dataType: 'json',
statusCode:
200: function(response) // success
var listings = response.features;
//console.log(listings);
for (var i = 0; i < listings.length; i++)
var feature = listings[i];
if (feature.properties.formatted.toLowerCase().search(query.toLowerCase()) !== -1)
feature['place_name'] = '🚙 ' + feature.properties.formatted;
feature['center'] = feature.geometry.coordinates;
matchingFeatures.push(feature);
console.log(matchingFeatures);
return matchingFeatures;
,
402: function()
console.log('hit free-trial daily limit');
console.log('become a customer: https://opencagedata.com/pricing');
);
Console output from this function:
0:
center: (2) [145.516244, -37.4666249]
geometry: coordinates: Array(2), type: "Point"
place_name: "🚙 Aeroplane Track, Toolangi VIC, Australia"
properties:
annotations: DMS: …, MGRS: "55HCU6878852327", Maidenhead: "QF22sm18wa", Mercator: …, OSM: …, …
bounds: northeast: …, southwest: …
components: ISO_3166-1_alpha-2: "AU", ISO_3166-1_alpha-3: "AUS", _type: "road", continent: "Oceania", country: "Australia", …
confidence: 7
formatted: "Aeroplane Track, Toolangi VIC, Australia"
__proto__: Object
type: "Feature"
__proto__: Object
length: 1
__proto__: Array(0)
I am able to get results of the geocode to appear correctly (in the same format as the local data version) in the console (console.log(matchingFeatures)
) but the subsequent return matchingFeatures
doesnt seem to work to add them to the mapbox geocoder results.
Been searching around for days with no luck. Annoyingly I feel like this is a common problem as the Mapbox geocoder results are lacking in many ways.
geocoding mapbox point-of-interest
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I am still learning JS so please bear with me.
I have built a Mapbox GL JS map and would like to supplement Mapbox geocoding results with those from an external geocoding API as many POIs I need are not returned with the standard Mapbox geocoder (such as campsites and national parks).
I have followed the tutorial to supplement results by querying local data here: Supplement forward geocoding search results from another data source
I have got this to work with local a geojson source however I cant get it to work when querying an external geocoder. I am testing with OpenCage.
My code for the geocoder instance on the map is:
// Load geojson source data
var myjson;
$.getJSON("<github hosted file>", function(json)
myjson = json;
);
// Local geocoder function
function forwardGeocoder(query)
var matchingFeatures = [];
for (var i = 0; i < myjson.features.length; i++)
var feature = myjson.features[i];
if (feature.properties.road_name.toLowerCase().search(query.toLowerCase()) !== -1)
feature['place_name'] = '🚙 ' + feature.properties.road_name;
feature['center'] = feature.geometry.coordinates;
matchingFeatures.push(feature);
return matchingFeatures;
//Add geocoder/search box
var geocoder = new MapboxGeocoder(
accessToken: mapboxgl.accessToken,
localGeocoder: forwardGeocoder,
country: 'au'
);
This works fine for local data pulled in from a geojson source (i.e. already loaded in the client side). When I try to add an external geocoder into the forwardGeocoder()
function, the query returns the correct geocoded results and I can get them to appear in the console but they dont appear in the standard mapbox geocoder results list. Code for the external geocoder (using OpenCage to test).
function forwardGeocoder(query)
var matchingFeatures = [];
$.ajax(
url: 'https://api.opencagedata.com/geocode/v1/geojson',
method: 'GET',
data:
'key': 'ab6ad6e3ad3043e2aeb897322ab038f0',
'q': query,
'pretty': 1
,
dataType: 'json',
statusCode:
200: function(response) // success
var listings = response.features;
//console.log(listings);
for (var i = 0; i < listings.length; i++)
var feature = listings[i];
if (feature.properties.formatted.toLowerCase().search(query.toLowerCase()) !== -1)
feature['place_name'] = '🚙 ' + feature.properties.formatted;
feature['center'] = feature.geometry.coordinates;
matchingFeatures.push(feature);
console.log(matchingFeatures);
return matchingFeatures;
,
402: function()
console.log('hit free-trial daily limit');
console.log('become a customer: https://opencagedata.com/pricing');
);
Console output from this function:
0:
center: (2) [145.516244, -37.4666249]
geometry: coordinates: Array(2), type: "Point"
place_name: "🚙 Aeroplane Track, Toolangi VIC, Australia"
properties:
annotations: DMS: …, MGRS: "55HCU6878852327", Maidenhead: "QF22sm18wa", Mercator: …, OSM: …, …
bounds: northeast: …, southwest: …
components: ISO_3166-1_alpha-2: "AU", ISO_3166-1_alpha-3: "AUS", _type: "road", continent: "Oceania", country: "Australia", …
confidence: 7
formatted: "Aeroplane Track, Toolangi VIC, Australia"
__proto__: Object
type: "Feature"
__proto__: Object
length: 1
__proto__: Array(0)
I am able to get results of the geocode to appear correctly (in the same format as the local data version) in the console (console.log(matchingFeatures)
) but the subsequent return matchingFeatures
doesnt seem to work to add them to the mapbox geocoder results.
Been searching around for days with no luck. Annoyingly I feel like this is a common problem as the Mapbox geocoder results are lacking in many ways.
geocoding mapbox point-of-interest
I am still learning JS so please bear with me.
I have built a Mapbox GL JS map and would like to supplement Mapbox geocoding results with those from an external geocoding API as many POIs I need are not returned with the standard Mapbox geocoder (such as campsites and national parks).
I have followed the tutorial to supplement results by querying local data here: Supplement forward geocoding search results from another data source
I have got this to work with local a geojson source however I cant get it to work when querying an external geocoder. I am testing with OpenCage.
My code for the geocoder instance on the map is:
// Load geojson source data
var myjson;
$.getJSON("<github hosted file>", function(json)
myjson = json;
);
// Local geocoder function
function forwardGeocoder(query)
var matchingFeatures = [];
for (var i = 0; i < myjson.features.length; i++)
var feature = myjson.features[i];
if (feature.properties.road_name.toLowerCase().search(query.toLowerCase()) !== -1)
feature['place_name'] = '🚙 ' + feature.properties.road_name;
feature['center'] = feature.geometry.coordinates;
matchingFeatures.push(feature);
return matchingFeatures;
//Add geocoder/search box
var geocoder = new MapboxGeocoder(
accessToken: mapboxgl.accessToken,
localGeocoder: forwardGeocoder,
country: 'au'
);
This works fine for local data pulled in from a geojson source (i.e. already loaded in the client side). When I try to add an external geocoder into the forwardGeocoder()
function, the query returns the correct geocoded results and I can get them to appear in the console but they dont appear in the standard mapbox geocoder results list. Code for the external geocoder (using OpenCage to test).
function forwardGeocoder(query)
var matchingFeatures = [];
$.ajax(
url: 'https://api.opencagedata.com/geocode/v1/geojson',
method: 'GET',
data:
'key': 'ab6ad6e3ad3043e2aeb897322ab038f0',
'q': query,
'pretty': 1
,
dataType: 'json',
statusCode:
200: function(response) // success
var listings = response.features;
//console.log(listings);
for (var i = 0; i < listings.length; i++)
var feature = listings[i];
if (feature.properties.formatted.toLowerCase().search(query.toLowerCase()) !== -1)
feature['place_name'] = '🚙 ' + feature.properties.formatted;
feature['center'] = feature.geometry.coordinates;
matchingFeatures.push(feature);
console.log(matchingFeatures);
return matchingFeatures;
,
402: function()
console.log('hit free-trial daily limit');
console.log('become a customer: https://opencagedata.com/pricing');
);
Console output from this function:
0:
center: (2) [145.516244, -37.4666249]
geometry: coordinates: Array(2), type: "Point"
place_name: "🚙 Aeroplane Track, Toolangi VIC, Australia"
properties:
annotations: DMS: …, MGRS: "55HCU6878852327", Maidenhead: "QF22sm18wa", Mercator: …, OSM: …, …
bounds: northeast: …, southwest: …
components: ISO_3166-1_alpha-2: "AU", ISO_3166-1_alpha-3: "AUS", _type: "road", continent: "Oceania", country: "Australia", …
confidence: 7
formatted: "Aeroplane Track, Toolangi VIC, Australia"
__proto__: Object
type: "Feature"
__proto__: Object
length: 1
__proto__: Array(0)
I am able to get results of the geocode to appear correctly (in the same format as the local data version) in the console (console.log(matchingFeatures)
) but the subsequent return matchingFeatures
doesnt seem to work to add them to the mapbox geocoder results.
Been searching around for days with no luck. Annoyingly I feel like this is a common problem as the Mapbox geocoder results are lacking in many ways.
geocoding mapbox point-of-interest
geocoding mapbox point-of-interest
edited Feb 26 at 11:25
PolyGeo♦
53.8k1781245
53.8k1781245
asked Feb 26 at 0:02
jnuccjnucc
63
63
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
What you're trying to do won't work since the localGeocoder option to mapbox-gl-geocoder is synchronous, so it can't be used to supplement results from a 3rd party API without https://github.com/mapbox/mapbox-gl-geocoder/issues/157
Your best option is to either write the code to extend mapbox-gl-geocoder to do this, or write your own replacement of mapbox-gl-geocoder which can call two external services.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "79"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f313574%2fsupplement-mapbox-geocoder-results-with-external-geocoder-api%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
What you're trying to do won't work since the localGeocoder option to mapbox-gl-geocoder is synchronous, so it can't be used to supplement results from a 3rd party API without https://github.com/mapbox/mapbox-gl-geocoder/issues/157
Your best option is to either write the code to extend mapbox-gl-geocoder to do this, or write your own replacement of mapbox-gl-geocoder which can call two external services.
add a comment |
What you're trying to do won't work since the localGeocoder option to mapbox-gl-geocoder is synchronous, so it can't be used to supplement results from a 3rd party API without https://github.com/mapbox/mapbox-gl-geocoder/issues/157
Your best option is to either write the code to extend mapbox-gl-geocoder to do this, or write your own replacement of mapbox-gl-geocoder which can call two external services.
add a comment |
What you're trying to do won't work since the localGeocoder option to mapbox-gl-geocoder is synchronous, so it can't be used to supplement results from a 3rd party API without https://github.com/mapbox/mapbox-gl-geocoder/issues/157
Your best option is to either write the code to extend mapbox-gl-geocoder to do this, or write your own replacement of mapbox-gl-geocoder which can call two external services.
What you're trying to do won't work since the localGeocoder option to mapbox-gl-geocoder is synchronous, so it can't be used to supplement results from a 3rd party API without https://github.com/mapbox/mapbox-gl-geocoder/issues/157
Your best option is to either write the code to extend mapbox-gl-geocoder to do this, or write your own replacement of mapbox-gl-geocoder which can call two external services.
answered Feb 26 at 11:50
AndrewHarveyAndrewHarvey
1,117510
1,117510
add a comment |
add a comment |
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f313574%2fsupplement-mapbox-geocoder-results-with-external-geocoder-api%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown