1 | import _Qs from 'qs';
|
2 | var Qs = _Qs && _Qs.default ? _Qs.default : _Qs;
|
3 | import * as RED from './service';
|
4 | import { parameters } from './endPoints';
|
5 | const endpoints = {
|
6 | }
|
7 | var formatjson = '?format=json';
|
8 | var googleservice = RED.createRedService('https://maps.googleapis.com/maps', null, true);
|
9 | var queryKey = null;
|
10 | var directionsKey = null;
|
11 | export const queryOps = { result_type: 'street_address' }
|
12 | export default {
|
13 | setKey: (key) => {
|
14 | queryKey = key;
|
15 | },
|
16 | setDirectionsKey: key => {
|
17 | directionsKey = key;
|
18 | },
|
19 | getGeoCodes: async (latitude, longitude, query) => {
|
20 | query = query || queryOps;
|
21 | var qstring = Qs.stringify(Object.assign({}, {
|
22 | latlng: latitude + ',' + longitude,
|
23 | key: queryKey
|
24 | }, query
|
25 | ));
|
26 | return googleservice.get(parameters('api/geocode/json?') + qstring);
|
27 | },
|
28 | getDirections: async (origin, destination, query) => {
|
29 |
|
30 | query = query || {};
|
31 | if (!origin || !destination) {
|
32 | return Promise.reject('no origin provided');
|
33 | }
|
34 | var qstring = Qs.stringify(Object.assign({}, {
|
35 | origin: origin.latitude + ',' + origin.longitude,
|
36 | destination: destination.latitude + ',' + destination.longitude,
|
37 | key: directionsKey || queryKey
|
38 | },
|
39 | query
|
40 | ));
|
41 | return googleservice.get(parameters('api/directions/json?') + qstring);
|
42 | }
|
43 | }; |
\ | No newline at end of file |