Created
March 13, 2017 20:38
-
-
Save sunnygleason/6a7564d03ecb18e7c84bb29753e5829f to your computer and use it in GitHub Desktop.
PubNub Geocoding BLOCK w/ ESRI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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