Skip to content

Instantly share code, notes, and snippets.

@sunnygleason
Created March 13, 2017 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunnygleason/6a7564d03ecb18e7c84bb29753e5829f to your computer and use it in GitHub Desktop.
Save sunnygleason/6a7564d03ecb18e7c84bb29753e5829f to your computer and use it in GitHub Desktop.
PubNub Geocoding BLOCK w/ ESRI
export default (request) => {
let xhr = require('xhr');
let query = require('codec/query_string');
let apiUrl = 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates';
let queryParams = {
singleLine: request.message.text,
outFields: "*",
f: 'json'
};
let url = apiUrl + '?' + query.stringify(queryParams);
return xhr.fetch(url)
.then((response) => {
request.message.geocode = JSON.parse(response.body);
return request;
})
.catch((err) => {
console.log('error happened for XHR.fetch', err);
return request;
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment