Get addresses of a list of coordinates
I am building an angular application where I have a list of places coming from firestore as follow:
places =[
{"id":1,
"name": place 1,
"latitude": 40.713484,
"longitude": -74.006739},
{"id":2,
"name": place 2,
"latitude": 40.712801,
"longitude": 74.004936},
.....]
And the list goes for about 1000 item, I need to operate a function to get the address of each place and add it the item then update the firestore database with the item address.
I am using google maps API to get the address of each item.
What is the best way to loop over the list and for each item i want to get the address and update the database before the next item.
How to perform sequential functions in forEach?
Thanks in advance
add a comment |
I am building an angular application where I have a list of places coming from firestore as follow:
places =[
{"id":1,
"name": place 1,
"latitude": 40.713484,
"longitude": -74.006739},
{"id":2,
"name": place 2,
"latitude": 40.712801,
"longitude": 74.004936},
.....]
And the list goes for about 1000 item, I need to operate a function to get the address of each place and add it the item then update the firestore database with the item address.
I am using google maps API to get the address of each item.
What is the best way to loop over the list and for each item i want to get the address and update the database before the next item.
How to perform sequential functions in forEach?
Thanks in advance
1
You mean that? developers.google.com/maps/documentation/javascript/examples/…
– Jacopo Sciampi
Nov 21 '18 at 7:32
I can't see any addresses in your array. Do you want to look them up somewhere?
– Daniel B
Nov 21 '18 at 7:32
I want to add the addresses to the items through google maps api
– Mohamed Essam
Nov 21 '18 at 7:36
add a comment |
I am building an angular application where I have a list of places coming from firestore as follow:
places =[
{"id":1,
"name": place 1,
"latitude": 40.713484,
"longitude": -74.006739},
{"id":2,
"name": place 2,
"latitude": 40.712801,
"longitude": 74.004936},
.....]
And the list goes for about 1000 item, I need to operate a function to get the address of each place and add it the item then update the firestore database with the item address.
I am using google maps API to get the address of each item.
What is the best way to loop over the list and for each item i want to get the address and update the database before the next item.
How to perform sequential functions in forEach?
Thanks in advance
I am building an angular application where I have a list of places coming from firestore as follow:
places =[
{"id":1,
"name": place 1,
"latitude": 40.713484,
"longitude": -74.006739},
{"id":2,
"name": place 2,
"latitude": 40.712801,
"longitude": 74.004936},
.....]
And the list goes for about 1000 item, I need to operate a function to get the address of each place and add it the item then update the firestore database with the item address.
I am using google maps API to get the address of each item.
What is the best way to loop over the list and for each item i want to get the address and update the database before the next item.
How to perform sequential functions in forEach?
Thanks in advance
edited Nov 21 '18 at 7:37
Mohamed Essam
asked Nov 21 '18 at 7:29
Mohamed EssamMohamed Essam
11
11
1
You mean that? developers.google.com/maps/documentation/javascript/examples/…
– Jacopo Sciampi
Nov 21 '18 at 7:32
I can't see any addresses in your array. Do you want to look them up somewhere?
– Daniel B
Nov 21 '18 at 7:32
I want to add the addresses to the items through google maps api
– Mohamed Essam
Nov 21 '18 at 7:36
add a comment |
1
You mean that? developers.google.com/maps/documentation/javascript/examples/…
– Jacopo Sciampi
Nov 21 '18 at 7:32
I can't see any addresses in your array. Do you want to look them up somewhere?
– Daniel B
Nov 21 '18 at 7:32
I want to add the addresses to the items through google maps api
– Mohamed Essam
Nov 21 '18 at 7:36
1
1
You mean that? developers.google.com/maps/documentation/javascript/examples/…
– Jacopo Sciampi
Nov 21 '18 at 7:32
You mean that? developers.google.com/maps/documentation/javascript/examples/…
– Jacopo Sciampi
Nov 21 '18 at 7:32
I can't see any addresses in your array. Do you want to look them up somewhere?
– Daniel B
Nov 21 '18 at 7:32
I can't see any addresses in your array. Do you want to look them up somewhere?
– Daniel B
Nov 21 '18 at 7:32
I want to add the addresses to the items through google maps api
– Mohamed Essam
Nov 21 '18 at 7:36
I want to add the addresses to the items through google maps api
– Mohamed Essam
Nov 21 '18 at 7:36
add a comment |
1 Answer
1
active
oldest
votes
Use geocode api of google maps, that should give you the address
this.http.get('https://maps.googleapis.com/maps/api/geocode/json?latlng=' + lat + ',' + lng + '&key=your_api_key')
.subscribe((getplaceData) => {
let address = { address: getplaceData['results'][0].formatted_address, coords: data};
}, err => {
console.log(JSON.stringify(err));
});
Since you have an array of coordinates, I will use Rxjs forkJoin
const arrayOfCalls = ;
place.forEach(pl => {
arrayOfCalls.push(
'https://maps.googleapis.com/maps/api/geocode/json?latlng=' + pl.lat + ',' + pl.lng + '&key=your_api_key'
)
})
forkJoin(ArrayOfCalls).subscribe((data)=> {
console.log(data)
})
Hope that helps
Many Thanks .....
– Mohamed Essam
Nov 21 '18 at 7:55
Can you help with the loop code
– Mohamed Essam
Nov 21 '18 at 7:55
here you go, good luck mate!!
– freepowder
Nov 21 '18 at 8:27
is not the solution good enough ... ?
– freepowder
Nov 21 '18 at 8:48
Many Thanks for your kind help
– Mohamed Essam
Nov 21 '18 at 12:03
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53407158%2fget-addresses-of-a-list-of-coordinates%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use geocode api of google maps, that should give you the address
this.http.get('https://maps.googleapis.com/maps/api/geocode/json?latlng=' + lat + ',' + lng + '&key=your_api_key')
.subscribe((getplaceData) => {
let address = { address: getplaceData['results'][0].formatted_address, coords: data};
}, err => {
console.log(JSON.stringify(err));
});
Since you have an array of coordinates, I will use Rxjs forkJoin
const arrayOfCalls = ;
place.forEach(pl => {
arrayOfCalls.push(
'https://maps.googleapis.com/maps/api/geocode/json?latlng=' + pl.lat + ',' + pl.lng + '&key=your_api_key'
)
})
forkJoin(ArrayOfCalls).subscribe((data)=> {
console.log(data)
})
Hope that helps
Many Thanks .....
– Mohamed Essam
Nov 21 '18 at 7:55
Can you help with the loop code
– Mohamed Essam
Nov 21 '18 at 7:55
here you go, good luck mate!!
– freepowder
Nov 21 '18 at 8:27
is not the solution good enough ... ?
– freepowder
Nov 21 '18 at 8:48
Many Thanks for your kind help
– Mohamed Essam
Nov 21 '18 at 12:03
|
show 1 more comment
Use geocode api of google maps, that should give you the address
this.http.get('https://maps.googleapis.com/maps/api/geocode/json?latlng=' + lat + ',' + lng + '&key=your_api_key')
.subscribe((getplaceData) => {
let address = { address: getplaceData['results'][0].formatted_address, coords: data};
}, err => {
console.log(JSON.stringify(err));
});
Since you have an array of coordinates, I will use Rxjs forkJoin
const arrayOfCalls = ;
place.forEach(pl => {
arrayOfCalls.push(
'https://maps.googleapis.com/maps/api/geocode/json?latlng=' + pl.lat + ',' + pl.lng + '&key=your_api_key'
)
})
forkJoin(ArrayOfCalls).subscribe((data)=> {
console.log(data)
})
Hope that helps
Many Thanks .....
– Mohamed Essam
Nov 21 '18 at 7:55
Can you help with the loop code
– Mohamed Essam
Nov 21 '18 at 7:55
here you go, good luck mate!!
– freepowder
Nov 21 '18 at 8:27
is not the solution good enough ... ?
– freepowder
Nov 21 '18 at 8:48
Many Thanks for your kind help
– Mohamed Essam
Nov 21 '18 at 12:03
|
show 1 more comment
Use geocode api of google maps, that should give you the address
this.http.get('https://maps.googleapis.com/maps/api/geocode/json?latlng=' + lat + ',' + lng + '&key=your_api_key')
.subscribe((getplaceData) => {
let address = { address: getplaceData['results'][0].formatted_address, coords: data};
}, err => {
console.log(JSON.stringify(err));
});
Since you have an array of coordinates, I will use Rxjs forkJoin
const arrayOfCalls = ;
place.forEach(pl => {
arrayOfCalls.push(
'https://maps.googleapis.com/maps/api/geocode/json?latlng=' + pl.lat + ',' + pl.lng + '&key=your_api_key'
)
})
forkJoin(ArrayOfCalls).subscribe((data)=> {
console.log(data)
})
Hope that helps
Use geocode api of google maps, that should give you the address
this.http.get('https://maps.googleapis.com/maps/api/geocode/json?latlng=' + lat + ',' + lng + '&key=your_api_key')
.subscribe((getplaceData) => {
let address = { address: getplaceData['results'][0].formatted_address, coords: data};
}, err => {
console.log(JSON.stringify(err));
});
Since you have an array of coordinates, I will use Rxjs forkJoin
const arrayOfCalls = ;
place.forEach(pl => {
arrayOfCalls.push(
'https://maps.googleapis.com/maps/api/geocode/json?latlng=' + pl.lat + ',' + pl.lng + '&key=your_api_key'
)
})
forkJoin(ArrayOfCalls).subscribe((data)=> {
console.log(data)
})
Hope that helps
edited Nov 21 '18 at 8:26
answered Nov 21 '18 at 7:47
freepowderfreepowder
2976
2976
Many Thanks .....
– Mohamed Essam
Nov 21 '18 at 7:55
Can you help with the loop code
– Mohamed Essam
Nov 21 '18 at 7:55
here you go, good luck mate!!
– freepowder
Nov 21 '18 at 8:27
is not the solution good enough ... ?
– freepowder
Nov 21 '18 at 8:48
Many Thanks for your kind help
– Mohamed Essam
Nov 21 '18 at 12:03
|
show 1 more comment
Many Thanks .....
– Mohamed Essam
Nov 21 '18 at 7:55
Can you help with the loop code
– Mohamed Essam
Nov 21 '18 at 7:55
here you go, good luck mate!!
– freepowder
Nov 21 '18 at 8:27
is not the solution good enough ... ?
– freepowder
Nov 21 '18 at 8:48
Many Thanks for your kind help
– Mohamed Essam
Nov 21 '18 at 12:03
Many Thanks .....
– Mohamed Essam
Nov 21 '18 at 7:55
Many Thanks .....
– Mohamed Essam
Nov 21 '18 at 7:55
Can you help with the loop code
– Mohamed Essam
Nov 21 '18 at 7:55
Can you help with the loop code
– Mohamed Essam
Nov 21 '18 at 7:55
here you go, good luck mate!!
– freepowder
Nov 21 '18 at 8:27
here you go, good luck mate!!
– freepowder
Nov 21 '18 at 8:27
is not the solution good enough ... ?
– freepowder
Nov 21 '18 at 8:48
is not the solution good enough ... ?
– freepowder
Nov 21 '18 at 8:48
Many Thanks for your kind help
– Mohamed Essam
Nov 21 '18 at 12:03
Many Thanks for your kind help
– Mohamed Essam
Nov 21 '18 at 12:03
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53407158%2fget-addresses-of-a-list-of-coordinates%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You mean that? developers.google.com/maps/documentation/javascript/examples/…
– Jacopo Sciampi
Nov 21 '18 at 7:32
I can't see any addresses in your array. Do you want to look them up somewhere?
– Daniel B
Nov 21 '18 at 7:32
I want to add the addresses to the items through google maps api
– Mohamed Essam
Nov 21 '18 at 7:36