Skip to content

Commit

Permalink
Merge pull request #2 from aashari/v1.2
Browse files Browse the repository at this point in the history
enable support language customization
  • Loading branch information
aashari authored Mar 13, 2023
2 parents 18f4f2f + 1eec252 commit b7dd68b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
16 changes: 16 additions & 0 deletions examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,19 @@ geocoding.encode("jalan merdeka utara no.3 jakarta").then(result => {
}
]*/
});

geocoding.encode("jalan merdeka utara no.3 jakarta", "id").then(result => {
console.log(result);
/*[
{
latitude: -6.175308299999999,
longitude: 106.8281502,
formatted_address: 'Jalan Medan Merdeka Utara No.3, RT.3/RW.2, Gambir, Kota Jakarta Pusat, Jakarta'
},
{
latitude: -6.1714815,
longitude: 106.8269598,
formatted_address: 'Jalan Medan Merdeka Utara, RT.3/RW.2, Gambir, Kota Jakarta Pusat, Jakarta'
}
]*/
});
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ let tryParseJSON = (json: string): any => {
}
}

export async function encode(formattedAddress: string): Promise<Location[]> {
export async function encode(formattedAddress: string, language: string = 'en'): Promise<Location[]> {

let locationList: Location[] = [];

let googleResponse = await get(`https://www.google.com/s?gs_ri=maps&authuser=0&hl=en&pb=!2i15!4m12!1m3!1d39925620.84463408!2d0!3d0!2m3!1f0!2f0!3f0!3m2!1i1015!2i939!4f13.1!7i20!10b1!12m8!1m1!18b1!2m3!5m1!6e2!20e3!10b1!16b1!19m4!2m3!1i360!2i120!4i8!20m57!2m2!1i203!2i100!3m2!2i4!5b1!6m6!1m2!1i86!2i86!1m2!1i408!2i240!7m42!1m3!1e1!2b0!3e3!1m3!1e2!2b1!3e2!1m3!1e2!2b0!3e3!1m3!1e8!2b0!3e3!1m3!1e10!2b0!3e3!1m3!1e10!2b1!3e2!1m3!1e9!2b1!3e2!1m3!1e10!2b0!3e3!1m3!1e10!2b1!3e2!1m3!1e10!2b0!3e4!2b1!4b1!9b0!22m3!1s_lJEYqe4D8_F4-EP4o-HoAM!3b1!7e81!23m2!4b1!10b1!24m65!1m21!13m8!2b1!3b1!4b1!6i1!8b1!9b1!14b1!20b1!18m11!3b1!4b1!5b1!6b1!9b1!12b1!13b1!14b1!15b1!17b1!20b1!2b1!5m5!2b1!3b1!5b1!6b1!7b1!10m1!8e3!14m1!3b1!17b1!20m2!1e3!1e6!24b1!25b1!26b1!29b1!30m1!2b1!36b1!43b1!52b1!54m1!1b1!55b1!56m2!1b1!3b1!65m5!3m4!1m3!1m2!1i224!2i298!71b1!72m4!1m2!3b1!5b1!4b1!89b1!26m4!2m3!1i80!2i92!4i8!34m17!2b1!3b1!4b1!6b1!8m5!1b1!3b1!4b1!5b1!6b1!9b1!12b1!14b1!20b1!23b1!25b1!26b1!37m1!1e81!47m0!49m5!3b1!6m1!1b1!7m1!1e3!67m2!7b1!10b1!69i596&q=${encodeURI(formattedAddress)}`);
let googleResponse = await get(`https://www.google.com/s?gs_ri=maps&authuser=0&hl=${language}&pb=!2i15!4m12!1m3!1d39925620.84463408!2d0!3d0!2m3!1f0!2f0!3f0!3m2!1i1015!2i939!4f13.1!7i20!10b1!12m8!1m1!18b1!2m3!5m1!6e2!20e3!10b1!16b1!19m4!2m3!1i360!2i120!4i8!20m57!2m2!1i203!2i100!3m2!2i4!5b1!6m6!1m2!1i86!2i86!1m2!1i408!2i240!7m42!1m3!1e1!2b0!3e3!1m3!1e2!2b1!3e2!1m3!1e2!2b0!3e3!1m3!1e8!2b0!3e3!1m3!1e10!2b0!3e3!1m3!1e10!2b1!3e2!1m3!1e9!2b1!3e2!1m3!1e10!2b0!3e3!1m3!1e10!2b1!3e2!1m3!1e10!2b0!3e4!2b1!4b1!9b0!22m3!1s_lJEYqe4D8_F4-EP4o-HoAM!3b1!7e81!23m2!4b1!10b1!24m65!1m21!13m8!2b1!3b1!4b1!6i1!8b1!9b1!14b1!20b1!18m11!3b1!4b1!5b1!6b1!9b1!12b1!13b1!14b1!15b1!17b1!20b1!2b1!5m5!2b1!3b1!5b1!6b1!7b1!10m1!8e3!14m1!3b1!17b1!20m2!1e3!1e6!24b1!25b1!26b1!29b1!30m1!2b1!36b1!43b1!52b1!54m1!1b1!55b1!56m2!1b1!3b1!65m5!3m4!1m3!1m2!1i224!2i298!71b1!72m4!1m2!3b1!5b1!4b1!89b1!26m4!2m3!1i80!2i92!4i8!34m17!2b1!3b1!4b1!6b1!8m5!1b1!3b1!4b1!5b1!6b1!9b1!12b1!14b1!20b1!23b1!25b1!26b1!37m1!1e81!47m0!49m5!3b1!6m1!1b1!7m1!1e3!67m2!7b1!10b1!69i596&q=${encodeURI(formattedAddress)}`);

let rawCleaningFiltered: any[] = googleResponse?.split("\n")
.map(line => tryParseJSON(line.trim()))
Expand Down Expand Up @@ -47,14 +47,14 @@ export async function encode(formattedAddress: string): Promise<Location[]> {

}

export async function decode(latitude: number, longitude: number): Promise<Location | null> {
export async function decode(latitude: number, longitude: number, language: string = 'en'): Promise<Location | null> {

let location: Location = {
latitude: latitude,
longitude: longitude,
};

let googleResponse = await get(`https://www.google.com/maps/search/?api=1&query=${location.latitude}%2C${location.longitude}`);
let googleResponse = await get(`https://www.google.com/maps/search/?api=1&hl=${language}&query=${location.latitude}%2C${location.longitude}`);

let finalFiltered: string[] = [];
let rawCleaningFiltered: [any] | any = [];
Expand Down

0 comments on commit b7dd68b

Please sign in to comment.