Utils for geocoding.
Install the package in your project directory with:
// with npm
npm install @geocoder-free/utils
// with yarn
yarn add @geocoder-free/utils
<script src="https://cdn.jsdelivr.net/npm/@geocoder-free/utils@0.2.8/umd/geocoderfreeutils.min.js"></script>
If you want to use HttpClient in server, node-fetch is required:
// with npm
npm install node-fetch
// with yarn
yarn add node-fetch
If you want to use HttpClient in client, fetch-jsonp is required:
// with npm
npm install fetch-jsonp
// with yarn
yarn add fetch-jsonp
- How to import
- HttpClient
- Get: fetch data by url. using jsonp in client and node-fetch in server to avoid CORS errors in client.
- GetUrl: get redirected url.
- Post: post and get data by url. using jsonp in client and node-fetch in server to avoid CORS errors in client.
- Functions for all
- Functions for Japan only
import { xxx } from '@geocoder-free/utils';
eg: import { dms2deg } from '@geocoder-free/utils';
const { xxx } = GeocoderFreeUtils;
eg: const { dms2deg } = GeocoderFreeUtils;
Packages node-fetch and fetch-jsonp are required by HttpClient.
jsonp mode Can be disabled by pasing true to the 3rd parameter.
| No. |
Parameter |
Required |
Type |
Default |
Description |
| 1 |
url |
〇 |
string |
|
|
| 2 |
returnType |
|
string |
'json' |
type of response, 'json' or 'text' |
| 3 |
forceNodeFetch |
|
boolean |
false |
if true, fetching data by jsonp will be disabled. |
import { Get } from '@geocoder-free/utils/HttpClient';
Get(`https://api.google.com/xxxxxx`).then(console.log);
Get the redirected url.
| No. |
Parameter |
Required |
Type |
Default |
Description |
| 1 |
url |
〇 |
string |
|
|
import { GetUrl } from '@geocoder-free/utils/HttpClient';
GetUrl(`https://goo.gl/maps/nQjjgsyid7iGa42J8`).then(console.log);
jsonp mode Can be disabled by pasing true to the 3rd parameter.
| No. |
Parameter |
Required |
Type |
Default |
Description |
| 1 |
url |
〇 |
string |
|
|
| 2 |
data |
〇 |
object |
|
data for post |
| 3 |
forceNodeFetch |
|
boolean |
false |
if true, fetching data by jsonp will be disabled. |
import { Post } from '@geocoder-free/utils/HttpClient';
Post(`https://api.google.com/xxxxxx`).then(console.log);
| No. |
Parameter |
Required |
Type |
Default |
Description |
| 1 |
dmsStr |
〇 |
string |
|
dms string |
dms2deg(`35°39'31.3"N`);
dms2deg(`139°44'40.3"W`);
| No. |
Parameter |
Required |
Type |
Default |
Description |
| 1 |
latlngDmsStr |
〇 |
string |
|
string contains dms latitude & dms longitude |
getLatLngByDMSStr(`35°39'31.3"N+139°44'40.3"E`);
| No. |
Parameter |
Required |
Type |
Default |
Description |
| 1 |
latlngDecimalStr |
〇 |
string |
|
string contains decimal latitude & decimal longitude(split by comma) |
getLatLngByDecimalStr(`35.123, 149.123`);
| No. |
Parameter |
Required |
Type |
Default |
Description |
| 1 |
latLngInDegr |
〇 |
array |
|
list of LatLngArray ([latitude, longitude]) |
getLatLngCentroid([[35.123, 139.234], [35.456, 139.567]]);
| No. |
Parameter |
Required |
Type |
Default |
Description |
| 1 |
latlngDecimalStr |
〇 |
string |
|
string contains decimal latitude & decimal longitude(split by comma) |
getLatLngObj(`35.123, 149.123`);
| No. |
Parameter |
Required |
Type |
Default |
Description |
| 1 |
dateStr |
〇 |
string |
|
output is different in different timezone |
getLocaleString(`2019-08-29`);
| No. |
Parameter |
Required |
Type |
Default |
Description |
| 1 |
msg |
〇 |
string |
|
message |
| 2 |
func |
|
function |
null |
call func(formatted string) if func is not null |
logFormat(`hello`);
logFormat(`hello`, (str) => `[info]${str}`);
| No. |
Parameter |
Required |
Type |
Default |
Description |
| 1 |
str |
〇 |
string |
|
|
removeSpace(' 2 3 4 ');
| No. |
Parameter |
Required |
Type |
Default |
Description |
| 1 |
latlngArr |
〇 |
array |
|
[latitude, longitude] |
isCorrectLatLng([NaN, 139.1]);
isCorrectLatLng([35.123, NaN]);
isCorrectLatLng([35.123, 139.1]);
| No. |
Parameter |
Required |
Type |
Default |
Description |
| 1 |
dateStr |
〇 |
string |
|
|
| 2 |
timezone |
〇 |
number |
|
|
getTimeByTimezone('2019-09-01 11:00:00', 9);
new Date('2019-09-01 11:00:00').getTime();
| No. |
Parameter |
Required |
Type |
Default |
Description |
| 1 |
date |
〇 |
string / date |
|
|
| 2 |
format |
|
string |
yyyy/MM/dd HHss |
for '2019-01-09 0801', yyyy: 2019; yy: 19; MM: 01; M: 1; dd: 09; d: 9; HH: 08; H: 8; mm: 01; m: 1; ss: 01; s: 1; SSS: 000; |
formatDate('2019-09-01 8:00:00', 'yyyy/M/d H:m:s');
番地までの住所を取得
| No. |
Parameter |
Required |
Type |
Default |
Description |
| 1 |
address |
〇 |
string |
|
番地の後ろにスペースが必要 |
cutToBlockNumber('新宿区 2-3-1 新宿ビル305');
郵便マーク(〒)を削除
removePostCode('〒123-1234+tokyo');
This project is licensed under the terms of the
MIT license.