@mapquest/geocoding
Advanced tools
Comparing version 0.0.3 to 0.0.4
26
index.js
@@ -42,2 +42,13 @@ 'use strict'; | ||
function covertToGeoJson(location){ | ||
return { | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [location.latLng.lng, location.latLng.lat] | ||
}, | ||
"properties": location | ||
} | ||
} | ||
class Geocoding { | ||
@@ -57,2 +68,17 @@ constructor(options){ | ||
forward(address){ | ||
return request | ||
.get(this.options.url + '/address') | ||
.query({key: this.options.key, | ||
location: address | ||
}) | ||
.then(response => response.body.results[0].locations[0]) | ||
.then(covertToGeoJson) | ||
.catch(err =>{ | ||
if(err.response && err.response.text) return Promise.reject(err.response.text); | ||
return Promise.reject(err); | ||
}) | ||
} | ||
reverse(lat, lng){ | ||
@@ -59,0 +85,0 @@ return request |
{ | ||
"name": "@mapquest/geocoding", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "MapQuest Geocoding", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# MQ Geocoding | ||
A JavaScript interface to the MapQuest geocoding service. You must obtain a key before using this service. This module | ||
can be used in the browser and server side. | ||
A JavaScript interface to the [MapQuest Geocoding API](https://developer.mapquest.com/documentation/geocoding-api/). | ||
You must obtain a key before using this service. This module can be used in the browser and server side. | ||
Examples: | ||
```javascript | ||
//setup the module | ||
const Geocoding = require('@mapquest/geocoding'); | ||
const client = new Geocoding({key: 'xxxxxxx'}) | ||
client.reverse(lat, lng) | ||
//forward geocode | ||
client.forward('1555 Blake St. Denver, CO 80204') | ||
.then(result => { | ||
console.log(result); // returns a GeoJson point of the first match | ||
}) | ||
//reverse geocode | ||
client.reverse(39.75, -104.99) //lat, lng | ||
.then(result => { | ||
console.log(result.addressString); //single line address, ie: "1555 Blake St., Denver, CO 80204" | ||
@@ -13,0 +23,0 @@ console.log(result.location); //geocoding service response |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11242
5
178
27